admin管理员组文章数量:1425763
I have a fresh VueJs project scaffold using the Vue CLI 3.0.4
I want to use SCSS variables inside all the ponents without having to import the _variables.scss
in all the ponents.
I want to import _variables.scss
and I found that can be done by using sass-resource-loader.
I've looked at all the answers around here and all are outdated as they do not work with vue-loader 15.
So inside vue.config.js
i have the following:
var path = require('path');
module.exports = {
chainWebpack: (config) => {
config.module
.rule('sass')
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve('./src/scss/config/_variables.scss'),
]
})
}
}
When I run this, I get the following error:
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
undefined
^
Undefined variable: "$brand-color".
in C:\dev\git\vue-typescript-test\src\ponents\HelloWorld.vue (line 60, column 10)
The $brand-color variable is used in the Helloworld.vue ponent so it seams the variables are not added.
I can't seem to understand why it does not work, as i followed the docs in the Vue CLI by the letter.
Also I want to point out that I followed the chosen answer here: Vue CLI 3 sass-resources-loader - Options.loaders undefined
Any help greatly appreciated.
Thank you!
I have a fresh VueJs project scaffold using the Vue CLI 3.0.4
I want to use SCSS variables inside all the ponents without having to import the _variables.scss
in all the ponents.
I want to import _variables.scss
and I found that can be done by using sass-resource-loader.
I've looked at all the answers around here and all are outdated as they do not work with vue-loader 15.
So inside vue.config.js
i have the following:
var path = require('path');
module.exports = {
chainWebpack: (config) => {
config.module
.rule('sass')
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve('./src/scss/config/_variables.scss'),
]
})
}
}
When I run this, I get the following error:
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
undefined
^
Undefined variable: "$brand-color".
in C:\dev\git\vue-typescript-test\src\ponents\HelloWorld.vue (line 60, column 10)
The $brand-color variable is used in the Helloworld.vue ponent so it seams the variables are not added.
I can't seem to understand why it does not work, as i followed the docs in the Vue CLI by the letter.
Also I want to point out that I followed the chosen answer here: Vue CLI 3 sass-resources-loader - Options.loaders undefined
Any help greatly appreciated.
Thank you!
Share Improve this question edited Oct 3, 2018 at 15:17 Constantin Chirila asked Oct 3, 2018 at 14:49 Constantin ChirilaConstantin Chirila 2,1392 gold badges20 silver badges33 bronze badges1 Answer
Reset to default 5It should work using this following code snippet.
module.exports = {
css: {
loaderOptions: {
sass: {
data: `@import "@/scss/config/_variables.scss";`
}
}
}
};
Note that @ is a shortcut to access the src folder.
Don't forget to install node-sass
and sass-loader
as well.
npm install --save-dev node-sass sass-loader
Finally, add the lang
attribute to your style
tags.
<style lang="scss">
// some style...
</style>
本文标签:
版权声明:本文标题:javascript - How to load a _variables.scss file for all Vue components using sass-resource-loader on Vue CLI 3.04? - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745444658a2658607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论