vue-cli3配置less以及相关问题解决

news/2024/7/10 1:46:15 标签: vue, less, webpack

第一种配置方式

npm install style-resources-loader vue-cli-plugin-style-resources-loader less-loader less -S
// vue.config.js 文件配置
const path = require('path')
module.exports = {
    pluginOptions: {
      'style-resources-loader': {
        preProcessor: 'less',
        patterns: [
          path.resolve(__dirname,'./src/assets/common/common.less')
        ]
      }
    }
}

第二种配置方式

npm install style-resources-loader -D
// vue.config.js 配置
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))
		})
	}
}
// add style resource
function addStyleResource (rule) {
	rule.use('style-resource')
		.loader('style-resources-loader')
		.options({
			patterns: [path.resolve(__dirname, './src/assets/common/common.less')]
		})
}

安装配置完之后,发现有报错信息,如下:
在这里插入图片描述
原因: less-loader安装的版本过高
解决方案:
1.npm uninstall less-loader
2.npm install less-loader@5.0.0


http://www.niftyadmin.cn/n/1355481.html

相关文章

js 获取select的值 / js动态给select赋值

jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText$("#select_id").find("option:selected").text(); //…

HTML5 jQuery图片上传前预览

<!DOCTYPE html><html><head><title>HTML5上传图片预览</title><meta http-equiv"Content-Type" content"text/html; charsetUTF-8"><script src"http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"&…

js字符串转换成数字,数字转换成字符串

将字符串转换成数字&#xff0c;得用到parseInt函数。parseInt(string) &#xff1a; 函数从string的开始解析&#xff0c;返回一个整数。 举例&#xff1a;parseInt(123) : 返回 123&#xff08;int&#xff09;&#xff1b; parseInt(1234xxx) : 返回 1234&#xff08;int&am…

将字符串形式的日期转换成日期对象

将字符串形式的日期转换成日期对象 var strTime"2011-04-16"; //字符串日期格式 var date new Date(Date.parse(strTime.replace(/-/g, "/"))); //转换成Data(); var monthdate.getMonth()1; //获取当前月份 -------------------------------…

js 格式化时间日期函数小结

js 格式化时间日期函数小结 Date.prototype.format function(format){ var o { "M" : this.getMonth()1, //month "d" : this.getDate(), //day "h" : this.getHours(), //hour "m" : this.getMinutes(), //minute "s" : …

JavaScript(js)设置默认输入焦点(focus)

常常会在回复和引用里使用此功能&#xff0c;即单击回复或引用&#xff0c;如让输入焦点出现在留言输入框中&#xff0c;如果使用锚来定位&#xff0c;输入焦点就不能激活了。 javascript:document.getElementById("id").focus(); 或javascript:document.all.id.…

JS中apply和call的联系和区别

JS中有时常用到 apply 和 call 两个方法&#xff0c;搜索网上很多&#xff0c;整理如下&#xff0c;简单看看这两个联系和区别&#xff0c; 联系: 网上查到关于apply和call的定义&#xff1a;这两个方法都能劫持另外一个对象的方法&#xff0c;继承另外一个对象的属性. xxxFun…

获取url参数

获取url参数document.location.href "ExChangeInfo.html?id" id;function getUrlParam(name) {var reg new RegExp("(^|&)" name "([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象var r window.location.search.sub…