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