babel-plugin-import
安装插件:
npm install babel-plugin-import --save
根目录建立.babelrc文件:
{
"plugins": [
["import", {
"libraryName": "antd", "libraryDirectory": "es", "style": "css" }]
]
}
或者在package.json中
"babel": {
"presets": [
"react-app"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"libraryDirectory": "es",
"style": "css"
}
]
]
},
如果报错:
Error: Multiple configuration files found. Please remove one: - package.json
表示.babelrc和package.json中出现了相同配置,取舍一个就可以了
然后只需从 antd 引入模块即可,无需单独引入样式,此时此刻这段代码也可以注释掉了
import 'antd/dist/antd.css';