vue3中全局引入less

1、安装less less-loader

javascript 复制代码
yarn add less less-loader

2、安装style-resources-loader

javascript 复制代码
yarn add style-resources-loader

3、安装vue-cli-plugin-style-resources-loader

javascript 复制代码
yarn add vue-cli-plugin-style-resources-loader

4、配置vue.config.js

如果没有则新建vue.config.js

javascript 复制代码
const path = require('path')
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
    transpileDependencies: true,
    pluginOptions: {
        "style-resources-loader": {
            preProcessor: "less",
            patterns: [
            path.resolve(__dirname,'./src/assets/css/base.less')
            ]
        }
    }
})

4.1 base.less

css 复制代码
@textColor: #99999;
@bgColor: #f2f3f4;
@lineHeight: 30px;
.textValue:{
    color: @textColor;
    line-height: @lineHeight;
}
相关推荐
大虾写代码13 分钟前
vue3+TS项目配置Eslint+prettier+husky语法校验
前端·vue·eslint
wordbaby31 分钟前
用 useEffectEvent 做精准埋点:React analytics pageview 场景的最佳实践与原理剖析
前端·react.js
上单带刀不带妹35 分钟前
在 ES6 中如何提取深度嵌套的对象中的指定属性
前端·ecmascript·es6
excel43 分钟前
使用热力贴图和高斯函数生成山峰与等高线的 WebGL Shader 解析
前端
wyzqhhhh1 小时前
组件库打包工具选型(npm/pnpm/yarn)的区别和技术考量
前端·npm·node.js
码上暴富1 小时前
vue2迁移到vite[保姆级教程]
前端·javascript·vue.js
土了个豆子的1 小时前
04.事件中心模块
开发语言·前端·visualstudio·单例模式·c#
全栈技术负责人2 小时前
Hybrid应用性能优化实战分享(本文iOS 与 H5为例,安卓同理)
前端·ios·性能优化·html5
xw52 小时前
移动端调试上篇
前端
@菜菜_达2 小时前
Lodash方法总结
开发语言·前端·javascript