vue-cli4项目引入sass的坑Cannot read property ‘style-resources-loader‘ of undefined

tech2022-09-17  116

尽管很久之前就用sass了,但是昨日用vuecli4创建项目后,引入sass一直失败, 一开始是提示

TypeError: Cannot read property ‘scss’ of undefined 使用npm i sass sass-loader --save后依然不行 依旧报错 错误为 TypeError: Cannot read property ‘style-resources-loader’ of undefined 解决办法:npm install sass-resources-loader --save-dev

附上vue.config.js配置css

const path = require('path') module.exports={ css: { requireModuleExtension: true, sourceMap: true, loaderOptions: { scss: { additionalData(content, loaderContext) { const { resourcePath, rootContext } = loaderContext; const relativePath = path.relative(rootContext, resourcePath); if ( relativePath.replace(/\\/g, "/") !== "src/styles/index.scss" ) { return '@import "~@/styles/index.scss";' + content; } return content; }, }, }, }, }
最新回复(0)