一、当你使用import { Button } from 'antd';这种方式引入组件的时候,没有做处理的时候,会加载antd下的所有模块,影响应用程序的网络性能。
二、可以使用使用import Button from 'antd/es/button'; import 'antd/es/button/style';这种方式按需加载。
三、可以继续使用import { Button } from 'antd';这种方式。使用 babel-plugin-import 来进行按需加载。插件会帮你转换成 antd/es/xxx 的写法。另外此插件配合 style 属性可以做到模块样式的按需自动加载。或者可以引入压缩的全局样式。
// .babelrc
{
"plugins": [["import", {
"libraryName": "antd",
"libraryDirectory": "es",// 默认是lib
"style": true
}
]]
}