今天在使用vue3 的项目中想引入scss的全局变量。直接百度了vue.config.js scss,然后得到的结果,大部分是
css: { loaderOptions: { sass: { prependData: `@import "@/assets/scss/_variable.scss";` //引入全局变量 } } }
然后编译,报错
ValidationError: Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'prependData'. These properties are valid: object { implementation?, sassOptions?, additionalData?, sourceMap?, webpackImporter? } at validate (C:\inetpub\wwwroot\t2\antd_t\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:104:11) at Object.loader (C:\inetpub\wwwroot\t2\antd_t\node_modules\sass-loader\dist\index.js:30:29)
作为一个懒人,我是没看完整个错误。直接百度scss has an unknown property 'prependData'。然后得到结论就是,npm和sass-loader的版本高了。
曾经使用gulp对layuiadmin,进行压缩构建的经历,让我知道版本高了,那么就是有东西需要改变。然后认真看了下错误,后面提示到These properties are valid:object { implementation?, sassOptions?, additionalData?, sourceMap?, webpackImporter? }。那么究竟是这五个中的,哪一个呢。正常来说additionalData和prependData都有Data,赶紧百度scss additionalData,从其他人的博客得到结果,就是这个没错。
修改,编译,正常。
css: { loaderOptions: { sass: { additionalData: `@import "@/assets/scss/_variable.scss";` //引入全局变量 } } }