vue3之引入less
一、安装相关内容
1、安装less、less-loader
npm install less-loader less --save-dev
2、安装style-resources-loader
说明:有时我们往往需要一些全局样式,但用@import导入未免麻烦,这时我们可以使用vue插件style-resources-loader;前提是已经安装了less、less-loader
npm install style-resources-loader --save-dev
3、安装vue-cli-plugin-style-resources-loader
npm install vue-cli-plugin-style-resources-loader --save-dev
二、配置
1、配置vue.config.js
const path = require('path'); module.exports = { transpileDependencies: [ 'vuetify' ], pluginOptions: { "style-resources-loader": { preProcessor: "less", patterns: [ // 引入公共文件 path.resolve(__dirname, "./src/assets/less/common.less") ] } }, css: { loaderOptions: { less: { lessOptions: { modifyVars: { 'primary-color': '#ec6800' }, javascriptEnabled: true, }, }, }, } }