react antd less(3.11.1) less-loader(5.0.0) webpack(4.42.0)设置antd的主题


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')}

 

 增加代码

  

if (preProcessor === "less-loader") {
        loaders.push(
          {
            loader: require.resolve(preProcessor),
            options: {
              sourceMap: isEnvProduction && shouldUseSourceMap,
              modifyVars: {
                '@primary-color':'#f40'
              },
              javascriptEnabled: true,
            },
          }
        );
 
  

 

切记开启

babel-plugin-import的less开关,否则设置主题不生效

 "plugins": [
      [
        "import",
        {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": true
        }
      ]
    ]
 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM