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';`
                }
            }
        }
    }
};

 

posted @ 2021-04-01 10:55  有点油  阅读(327)  评论(0)    收藏  举报