深坑react 引入antd無效問題


//安裝babel-plugin-import
第一步:
npm install babel-plugin-import --save




第二步:暴露webpack.config.js
運行:npm run eject


第三步:在webpack.config.js中的module下的oneOf數組里加入下面代碼:

 {//ES6、JSX處理
              test: /(\.jsx|\.js)$/,
              exclude: /node_modules/,
              loader: 'babel-loader',
              query:
              {
                plugins: [
                  [
                    "import",
                    { libraryName: "antd", style: 'css' }
                  ] //antd按需加載
                ]
              },
            },

            {//CSS處理
              test: /\.css$/,
              loader: "style-loader!css-loader?modules",
              exclude: /node_modules/,
            },

            {//antd樣式處理
              test: /\.css$/,
              exclude: /src/,
              use: [
                { loader: "style-loader", },
                {
                  loader: "css-loader",
                  options: {
                    importLoaders: 1
                  }
                }
              ]
            },

重啟項目即可;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM