【react學習二】create-react-app 接入antd 並按需加載組件


1.安裝

cnpm i babel-plugin-import --save-dev

2.使用

在根目錄下的package.json下的bable中添加相應代碼

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

3.重啟項目  npm start

你就能按需加載antd組件了, 像這樣

import { Button } from 'antd';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM