less(3.11.1) 配合6以上的less-loader会报错
ValidationError: Invalid options object. Less Loader has been initialized using an options object that does not match the API schema.
解决方案
链接:https://github.com/ant-design/ant-design/issues/23624
webpack.config.js配置步骤
配置less环境
在方法 getStyleLoaders,添加代码:
{loader:require.resolve('less-loader')}
![](https://img2020.cnblogs.com/blog/1338998/202005/1338998-20200510225525769-946944882.png)
增加代码
if (preProcessor === "less-loader") {
loaders.push(
{
loader: require.resolve(preProcessor),
options: {
sourceMap: isEnvProduction && shouldUseSourceMap,
modifyVars: {
'@primary-color':'#f40'
},
javascriptEnabled: true,
},
}
);
![](https://img2020.cnblogs.com/blog/1338998/202005/1338998-20200510225644421-43869478.png)
切记开启
babel-plugin-import的less开关,否则设置主题不生效
"plugins": [
[
"import",
{
"libraryName": "antd",
"libraryDirectory": "es",
"style": true
}
]
]
![](https://img2020.cnblogs.com/blog/1338998/202005/1338998-20200510225905459-741107620.png)