Vue集成less遇到的坑
vue的项目中使用lang=”less“在安装less-loader的时候经常会因为版本过高报错
Module build failed: TypeError: loaderContext.getResolve is not a function at createWebpackLessPlugin (C:\Users\EDZ\Desktop\nsf_enterprise\nsf_enterprise\node_modules\less-loader\dist\utils.js:31:33) at getLessOptions (C:\Users\EDZ\Desktop\nsf_enterprise\nsf_enterprise\node_modules\less-loader\dist\utils.js:148:31) at Object.lessLoader (C:\Users\EDZ\Desktop\nsf_enterprise\nsf_enterprise\node_modules\less-loader\dist\index.js:29:49) @ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-3d5f66de","scoped":true,"hasInlineConfig":false}!./node_modules/less-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/components/order/allOrder.vue 4:14-385 13:3-17:5 14:22-393 @ ./src/components/order/allOrder.vue @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
这是由于最新版本的less-loader与当前Vue版本不兼容
解决办法: 根据使用的Vue版本选择相应的less-loader版本
npm install less-loader@4.1.0