vue项目根据启动指令动态载入全局使用css文件

vue项目根据启动指令载入全局主题css

文件:package.json

"start": "vue-cli-service serve --themVersion bs"

文件:vue.config.js

//根据指令获取固定路径下的css文件

let themCssPathAry = [];
let roadAry = process.argv;
//去除前3位的路径和指令
roadAry.splice(0,3);
let themIndex = roadAry.indexOf('--themVersion');
if(themIndex !== -1){
  themCssPathAry.push(path.resolve(__dirname, `./src/assets/theme/${roadAry[themIndex+1]}.less`))
}
//在全局的扩展中载入添加的css文件
pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        path.resolve(__dirname, './src/assets/styles/*.less')
      ].concat(themCssPathAry)
    }
  },

以上!!

你可能感兴趣的:(vue.js,css,javascript)