- 引用ant-design-vue/dist/antd.less主题样式报错
./node_modules/ant-design-vue/dist/antd.less (./node_modules/css-loader/dist/cjs.js??ref–10-oneOf-3-1!./node_modules/postcss-loader/src??ref–10-oneOf-3-2!./node_modules/less-loader/dist/cjs.js??ref–10-oneOf-3-3!./node_modules/ant-design-vue/dist/antd.less)
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
// https://github.com/ant-design/ant-motion/issues/44
.bezierEasingMixin();
....
根据提示我们可以去https://github.com/ant-design/ant-motion/issues/44看到一个解决问题的帖子。
比较推荐的一种做法是创建一个vue.config.js文件,并写入
module.exports = {
css: {
loaderOptions: {
less: {
javascriptEnabled: true
}
}
}
}
但是在 less-loader 6.0 之前 这样配置就可以了,但是升级到了 6.0 就会报错
错误信息:
ERROR in ./node_modules/ant-design-vue/dist/antd.less (./node_modules/css-loader/dist/cjs.js??clonedRuleSet-34[0].rules[0].use[1]!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-34[0].rules[0].use[2]!./node_modules/less-loader/dist/cjs.js??clonedRuleSet-34[0].rules[0].use[3]!./node_modules/ant-design-vue/dist/antd.less)
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
ValidationError: Invalid options object. Less Loader has been initialized using an options object that does not match the API schema.
- options has an unknown property 'javascriptEnabled'. These properties are valid:
object { lessOptions?, additionalData?, sourceMap?, webpackImporter?, implementation? }
@ ./node_modules/ant-design-vue/dist/antd.less 4:14-241 15:3-20:5 16:22-249
@ ./src/main.js 10:0-39
如果less-loader版本大于6.0使用下面配置:
const { defineConfig } = require("@vue/cli-service");
module.exports = defineConfig({
transpileDependencies: true,
css: {
loaderOptions: {
less: {
lessOptions: {
javascriptEnabled: true,
math: "always",
}
}
}
}
});
如果是less4.x以上可以能出现如下错误:
Syntax Error:
position: absolute;
top: 8px + @font-size-base * @line-height-base / 2 - @font-size-base / 2;
^
Operation on an invalid type
less 4 语法有改动
top: 8px + @font-size-base * @line-height-base / 2 - @font-size-base / 2;
这个是不合法的,改成
top: 8px + (@font-size-base * @line-height-base / 2) - (@font-size-base / 2);
要么降级 less 到 3.x版本或者使用上边的兼容配置
vue.config.js的文件格式可以参看cli官网 两种方式根据自己情况选择。
|