方法一

1、添加依赖 style-resources-loader

2、vue.config.js中添加

module.exports = {
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [],
},
},
};

3、添加全局less引入

module.exports = {
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
path.resolve(__dirname, './src/assets/varibles.less'),
],
},
},
};

4、加入path

const path = require('path');

module.exports = {
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
path.resolve(__dirname, './src/assets/varibles.less'),
],
},
},
};

方法二

const path = require('path')

module.exports = {
chainWebpack: config => {
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)))
},
css: {
loaderOptions: {
less: {
javascriptEnabled: true
}
}
}
} function addStyleResource(rule) {
rule.use('style-resource')
.loader('style-resources-loader')
.options({
patterns: [
path.resolve(__dirname, 'src/styles/variable.less'), // 需要全局导入的less
],
})
}

方法三

module.exports = {
css: {
loaderOptions: {
less: {
globalVars: {
primary: '#fff'
}
}
}
}
}

最新文章

  1. .NET 对象生命周期
  2. bootstrap-fileinput简单完整列子
  3. C#的Invoke和BeginInvoke
  4. xmpp即时通讯的笔记(摘抄)
  5. VMware安装虚拟系统问题
  6. HMM 自学教程(一)引言
  7. apache 开启zgip 压缩模式
  8. 系统级I/O
  9. CCF真题之网络延时
  10. 字符串和date之间的相互转换方法
  11. FPGA代码设计规范整理
  12. 【C++深入浅出】设计模式学习之单例模式
  13. udp开发-dtd验证,dom解析
  14. Comparator TreeSet
  15. 【Linux】环境变量设置
  16. java中synchronized的使用方法与具体解释
  17. Struts2和SpringMVC的区别
  18. Jason Wang:记录自己所想所得(第一次作业)
  19. Swagger 配置
  20. 新装的arcgis10.5特别卡

热门文章

  1. Spring为什么@Autowired注入的是接口
  2. window server 2008 iis7+php安装配置
  3. 004-nginx简介、安装配置【源码安装和mac安装】、基本使用
  4. 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_15-认证接口开发-Redis配置
  5. QML异常:Cannot anchor to an item that isn't a parent or sibling
  6. python高级知识
  7. ideal配置使用Git
  8. delphi两个取字串长度的函数strlen,length
  9. 【Leetcode_easy】645. Set Mismatch
  10. laravel的workflow流程插件