美文网首页前端学习
给create-react-app生成的react添加antd-

给create-react-app生成的react添加antd-

作者: 小盐_814e | 来源:发表于2020-09-04 15:42 被阅读0次

先将项目拆包

yarn eject

安装babel-plugin-import

npm install babel-plugin-import --save-dev

找到package.json中的babel部分
修改为

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

即可实现antd-mobile按需加载,修改引用方式

- import Button from 'antd-mobile/lib/button';
+ import { Button } from 'antd-mobile';

同样pc端安装antd懒加载

yarn add antd

安装babel-plugin-import

npm install babel-plugin-import --save-dev

找到package.json中的babel部分
修改为

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

相关文章

网友评论

    本文标题:给create-react-app生成的react添加antd-

    本文链接:https://www.haomeiwen.com/subject/bjgzsktx.html