1.安装less、less-loader
npm i less-loader less --save-dev
2.安装style-resources-loader
npm i style-resources-loader --save-dev
3.安装vue-cli-plugin-style-resources-loader
npm i vue-cli-plugin-style-resources-loader --save-dev
4.配置vue.config.js
const path = require('path');
module.exports = {
transpileDependencies: [
'vuetify'
],
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: [
// 存放less变量文件的路径
path.resolve(__dirname, "./src/assets/less/parameter.less")
]
}
},
css: {
loaderOptions: {
less: {
lessOptions: {
modifyVars: {
'primary-color': '#ec6800'
},
javascriptEnabled: true,
},
},
},
}
}
注:如果安装以上插件,运行报错时:
Syntax Error: TypeError: this.getOptions is not a function
说明less版本太高了,卸载重装7.x版本即可
// 卸载
npm uninstall --save less-loader
// 安装
npm install -D less-loader@7.x