create-react-app支持antd按需导入

  • 按需加载配置
npm install react-app-rewired@2.0.2-next.0 babel-plugin-import --save
  • 在项目根目录下新建config-overrides.js
const { injectBabelPlugin } = require("react-app-rewired");
module.exports = function override(config, env) {
  config = injectBabelPlugin(
    [
      "import",
      {
        libraryName: "antd",
        libraryDirectory: "es",
        style: "css"
      }
    ],
    config
  );
  return config;
};
  • 修改package.json
"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject"
  }

即可完成antd组件按需导入

    原文作者:伍晓琳
    原文地址: https://segmentfault.com/a/1190000018280664
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞