babel-plugin-import配置babel按需引入antd模块

安装yarn add babel-plugin-import

运行  npm run eject 

打开package.json文件

"babel": { 

  "presets": [

    "react-app" 

  ]

添加配置

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins":
    [
      [
        "import",
        {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": "css"
        }
      ]
    ]
  }

相关推荐