antd css 按需加载

antd 对 css 按需加载介绍不甚详细,使用中遇到以下问题:

添加 .babelrc 无效

应先使用 npm eject 命令将配置暴露出来,命令介绍如下:

npm eject 介绍

不能直接添加 .babelrc 文件,否则报以下错

Multiple configuration files found. package.json#babel - .babelrc

解决方法:
1、删除 .babelrc 文件,在 package.json 中添加配置:

...
"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "import",
        {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": "css"
        }
      ]
    ]
  }
...

2、删除 package.json 中的 babel 配置,添加官网介绍的 .babelrc 文件;

使用第1种方法解决。

发布了43 篇原创文章 · 获赞 0 · 访问量 889

猜你喜欢

转载自blog.csdn.net/weixin_37562241/article/details/104328300