antd 按需引入

2019-12-24  本文已影响0人  Poiey

安装 antd

yarn add antd

再安装三款包

yarn add react-app-rewired customize-cra
yarn add babel-plugin-import

然后在项目根目录创建一个 config-overrides.js 用于修改默认配置。

const { override, fixBabelImports } = require('customize-cra');

module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd',
    libraryDirectory: 'es',
    style: 'css',
  }),
);

package.json文件更改成

  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject"
  },
上一篇 下一篇

猜你喜欢

热点阅读