javascript - Vue CLI 3 sass-resources-loader - Options.loaders undefined
问题描述
I was able to successfully configure a new Vue project using the 3.0 version of the CLI to use sass-resource-loader
a few weeks ago using the information posted here: Using sass-resources-loader with vue-cli v3.x
However, after updating everything today I'm encountering the following error when running npm run serve
:
TypeError: Cannot read property 'scss' of undefined
the only options that seem to be getting passed into .tap(options)
are:
{ compilerOptions: { preserveWhitespace: false } }
I don't currently know enough about chainWebpack
to effectively debug, but I'm working on it. If anyone has any insights into what's changed to cause this error, it'd be greatly appreciated.
my vue.config.js
:
const path = require('path')
module.exports = {
chainWebpack: (config) => {
config
.module
.rule('vue')
.use('vue-loader')
.tap((options) => {
console.log(options)
options.loaders.scss = options.loaders.scss.concat({
loader: 'sass-resources-loader',
options: {
resources: [
path.resolve('./src/scss/_variables.scss'),
path.resolve('./src/scss/_mixins.scss')
]
},
})
return options
})
config
.module
.rule('scss')
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve('./src/scss/_variables.scss'),
path.resolve('./src/scss/_mixins.scss')
]
})
}
}
解决方案
您使用vue-cli@3.x
,这可能意味着您的项目使用vue-loader@15.x
自版本 15 以来,vue-loader
加载程序不需要额外的配置。你只能配置你的主要 webpack 加载器。
const path = require('path')
module.exports = {
chainWebpack: (config) => {
config
.module
.rule('scss')
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve('./src/scss/_variables.scss'),
path.resolve('./src/scss/_mixins.scss')
]
})
}
}
vue inspect
您还可以使用or./node_modules/.bin/vue-cli-service inspect
命令检查 webpack 配置。
推荐阅读
- python - 有没有办法对远程会话进行身份验证以抓取数据并保持身份验证而不是在每个请求中进行身份验证?
- swift - Firebase Auth lastSignInDate 和 creationDate 比较失败
- ionic-framework - 如何在 ionic3 中更新时向 tabBadge 未读消息计数添加声音
- r - 使用 expss 包在 R 中的顶部 2 个 boxES 和底部 2 个盒子网
- reactjs - 将道具传递给新的 URL/路由
- html - href="../" 链接到根目录而不是父目录
- python - 如何使直方图条居中?
- angular - 如何从角度应用程序读取和写入本地文件
- gradle - Maven-Publish 未生成适当的任务
- amazon-web-services - 在 api 网关上启用 cors