报错环境: vue-cli 4.4.6 + iview 2.0
因为iview使用了less自定义主题样式,所以预编译的时候出现了如下错误:
98% after emitting CopyPlugin
ERROR Failed to compile with 1 errors 10:55:46 ├F10: AM┤
error in ./src/assets/custom-theme/custom.less
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
// https://github.com/ant-design/ant-motion/issues/44
.bezierEasingMixin();
^
Inline JavaScript is not enabled. Is it set in your options?
Error in D:\files\study\vue\web-client\node_modules\view-design\src\styles\color\bezierEasing.less (line 110, column 0)
@ ./src/assets/custom-theme/custom.less 4:14-238 14:3-18:5 15:22-246
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.19.169:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
解决:
找到如下文件位置
./node_modules/less-loader/dist/utils.js
function getLessOptions(loaderContext, loaderOptions) {
const options = (0, _clone.default)(loaderOptions.lessOptions typeof loaderOptions.lessOptions === 'function' loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions : {});
const lessOptions = {
plugins: [],
relativeUrls: true,
// 在这个位置添加这行代码==============================================
javascriptEnabled: true,
// We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
filename: loaderContext.resourcePath,
...options
};
lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
const useSourceMap = typeof loaderOptions.sourceMap === 'boolean' loaderOptions.sourceMap : loaderContext.sourceMap;
if (useSourceMap) {
lessOptions.sourceMap = {
outputSourceFiles: true
};
}
return lessOptions;
}
运行没问题。