前言:有时我们往往需要一些全局样式,但用@import导入未免麻烦,这时我们可以使用vue插件style-resources-loader;
使用步骤:
- npm安装:npm i style-resources-loader
- 在vue.config.js中使用:
const path = require('path');
function addStyleResource(rule) {
rule.use('style-resource')
.loader('style-resources-loader')
.options({
patterns: [
path.resolve(__dirname, './src/styles/imports.scss'),
],
})
}
module.exports = {
chainWebpack: config => {
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
types.forEach(type => addStyleResource(config.module.rule('scss').oneOf(type)))
},
}