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