better2021 / Blog

个人博客
https://feiyuweb.me/Blog
1 stars 0 forks source link

antd库的组件按需引入 #41

Open better2021 opened 3 years ago

better2021 commented 3 years ago
  1. 安装 babel-plugin-import 插件来按需加载组件

    yarn add babel-plugin-import --dev // 安装

  2. 在package.json中的babel处添加一下代码

    "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "import",
        {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": "css"
        }
      ]
    ]
    },
  3. 这样就不需要再引入样式文件,直接引入组件就可以按需加载了

import { Button } from "antd";