1. 程式人生 > >create-react-app 按需載入antd出錯問題解決

create-react-app 按需載入antd出錯問題解決

按需引入antd報錯問題 1.使用create-react-app工具建立了一個專案 create-react-app antd-demo 2.安裝babel-plugin-import npm install babel-plugin-import --dev 3.按需引用antd 在App.js裡面引入, import { Button } from 'antd'; package.json裡面配置babel

"babel": {
   "plugins": [
     [
       "import",
       {
         "libraryName": "antd",
         "style": true
       }
     ]
   ]
 },

最後專案啟動報錯,報錯資訊如下 ./node_modules/antd/lib/button/style/index.less Module build failed: // https://github.com/ant-design/ant-motion/issues/44 .bezierEasingMixin(); ^ Inline JavaScript is not enabled. Is it set in your options? in E:\webstrom\migu\ngoc\web\react-interface\react-interface-cli\node_modules\antd\lib\style\color\bezierEasing.less (line 110, column 0)

解決辦法:把最後的"style":true改為"style":"css"就可以了

這裡的style可以為true或者‘css’,但是不知道為什麼使用true就報錯,