vue-cli4 中 全局less变量配置
第一种
使用 vue-cli-plugin-style-resources-loader style-resources-loader
vue.config.js 配置
const path = require('path')
module.exports = {
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
// 这个是加上自己的路径,不能使用(如下:alias)中配置的别名路径
path.resolve(__dirname, './src/assets/global.less')
]
}
},
}
第二种
不需要 style-resources-loader 和 vue-cli-plugin-style-resources-loader
直接在vue.config.js 配置
module.exports = { css: { loaderOptions: { less: { globalVars: { hack: `true; @import '~@/assets/b.less';` } } } } };
一个幽默的前端爱好者,记录下自己的心得体会

浙公网安备 33010602011771号