• 按需加载配置
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组件按需导入


伍晓琳
5 声望0 粉丝