按需引入antd報錯問題

1.使用create-react-app工具建立了一個項目javascript

create-react-app antd-demo

2.安裝babel-plugin-importcss

npm install babel-plugin-import --dev

3.按需引用antdjava

在App.js裏面引入,node

import { Button } from 'antd';

package.json裏面配置babelreact

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

  最後項目啓動報錯,報錯信息以下git

./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":「css」就能夠了github

這裏的style能夠爲true或者‘css’,可是不知道爲何使用true就報錯,web

babel-plugin-import配置,options能夠爲數組npm

{  
  "plugins":[["import",options]]  
} 

導入js模塊:json

["import", { "libraryName": "antd" }]  

 導入js和css模塊(LESS/Sass源文件):

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

  導入js和css模塊(css 內置文件):

["import", { "libraryName": "antd", "style": "css" }]  
相關文章
相關標籤/搜索