VUE CLI3 less 全局变量引用
2024-09-05 03:21:02
方法一
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'
}
}
}
}
}
最新文章
- .NET 对象生命周期
- bootstrap-fileinput简单完整列子
- C#的Invoke和BeginInvoke
- xmpp即时通讯的笔记(摘抄)
- VMware安装虚拟系统问题
- HMM 自学教程(一)引言
- apache 开启zgip 压缩模式
- 系统级I/O
- CCF真题之网络延时
- 字符串和date之间的相互转换方法
- FPGA代码设计规范整理
- 【C++深入浅出】设计模式学习之单例模式
- udp开发-dtd验证,dom解析
- Comparator TreeSet
- 【Linux】环境变量设置
- java中synchronized的使用方法与具体解释
- Struts2和SpringMVC的区别
- Jason Wang:记录自己所想所得(第一次作业)
- Swagger 配置
- 新装的arcgis10.5特别卡
热门文章
- Spring为什么@Autowired注入的是接口
- window server 2008 iis7+php安装配置
- 004-nginx简介、安装配置【源码安装和mac安装】、基本使用
- 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_15-认证接口开发-Redis配置
- QML异常:Cannot anchor to an item that isn't a parent or sibling
- python高级知识
- ideal配置使用Git
- delphi两个取字串长度的函数strlen,length
- 【Leetcode_easy】645. Set Mismatch
- laravel的workflow流程插件