React antd 按需加载

1.手动加载组件

import Button from 'antd/lib/button'

import 'antd/lib/button/style'


2.暴露配置,配合babel-plugin-import插件实现按需加载

babel-plugin-import是一个用于按需加载组件和样式的babel插件


(1)暴露配置  npm run eject

(2)安装插件   npm install babel-plugin-import-S

(3)修改package.json

"babel": {

    "presets": [

      "react-app"

    ],

    "plugins": [

      [

        "import",

        {

          "libraryName": "antd",

          "libraryDirectory": "es",

          "style":"css"

        }

      ]

    ]

  }

配置完之后直接引入:import {Button} from ‘antd’

你可能感兴趣的:(React antd 按需加载)