sass-loader使用data引入公用文件或全局变量报错

报错信息:

ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.

报错写法如下:

复制代码
{
  loader: "sass-loader",
  options: {
    data: `
      $env: ${process.env.NODE_ENV};
@import "sass/_fn.scss"; @import "sass/_mixins.scss"; @import "sass/_var.scss"; ` } }
复制代码

 

报错原因:

新版sass-loader改了options参数名,把data改为了prependData,参考:https://github.com/webpack-contrib/sass-loader#prependdata

 

正确写法:

复制代码
{
  loader: "sass-loader",
  options: {
    prependData: `
      $env: ${process.env.NODE_ENV};
@import "sass/_fn.scss"; @import "sass/_mixins.scss"; @import "sass/_var.scss"; ` } }
复制代码

 

posted @ 2021-02-07 12:22  天午正阳  阅读(444)  评论(0编辑  收藏  举报