按需加载插件。只需要引入模块即可,无需单独引入样式。
import {Button} from 'antd';
ReactDom.render(
<div>
<Button>
XXXX
</Button>
</div>);
安装:
$ cnpm install babel-plugin-import --save-dev
装载:
{
"plugins":[["import",options]]
}
options 可以使 对象
style可以为true或者‘css’
{
"libraryName":"antd",
"style":true,
}
{
"libraryName": "material-ui",
"libraryDirectory": "components", // default: lib
"camel2DashComponentName": false, // default: true
}
options可以使一个数组
[
{
"libraryName": "antd",
"libraryDirectory": "lib", // default: lib
"style": true
},
{
"libraryName": "antd-mobile",
"libraryDirectory": "component",
},
]
样式:
导入js模块:
["import", { "libraryName": "antd" }]
导入js和css模块(LESS/Sass源文件):
["import", { "libraryName": "antd", "style": true }]
导入js和css模块(css 内置文件):
["import", { "libraryName": "antd", "style": "css" }]
注意:如果webpack配置文件添加了vendor库,babel-plugin-import将不会工作。