深坑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