create-react-app按需加载antd遇到的问题

create-react-app通过eject导出了配置后package.json怎么配置react-app-rewired的启动

阅读 5.7k
4 个回答

react-app-rewired的作用就是在不eject的情况下,覆盖create-react-app的配置。如果已经eject导出了配置,就没有必要使用react-app-rewired。

怎么配置react-app-rewired的启动? 这句话什么意思。
create-react-app里只需要按照官方的文档配置一下就好了。
https://ant.design/docs/react...

$ npm install -g create-react-app yarn
$ create-react-app antd-demo
$ cd antd-demo
$ yarn start
$ yarn add antd babel-plugin-import --save-dev
$ yarn eject
//给`package.json`中的`babel`添加如下代码:
"babel": {
  "presets": [
    "react-app"
  ],
  "plugins": [
    [
      "import",
      {
        "libraryName": "antd",
        "style": "css"
      }
    ]
  ]
}

这样就能在eject后按需加载啦

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题