1. Create a project using the create-react-app tool
|
1
|
create-react-app antd-demo |
2. Install babel-plugin-import
|
1
|
npm install babel-plugin-import --dev |
3. Quote antd on demand
Introduced in App.js,
|
1
|
import { Button } from 'antd'; |
Configure babel in package.json
|
1
2
3
4
5
6
7
8
9
10
11
|
"babel": { "plugins": [ [ "import", { "libraryName": "antd", "style": true } ] ] }, |
Finally, an error was reported when the project started, and the error message is as follows
|
1
2
3
4
5
6
7
8
|
./node_modules/antd/lib/button/style/index.lessModule 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) |
Finally put “style”: “css” on it
The style here can be true or’css’, but I don’t know why I use true and I get an error.
babel-plugin-import configuration, options can be an array
|
1
2
3
|
{ "plugins":[["import",options]] } |
Import the js module:
|
1
|
["import", { "libraryName": "antd" }] |
Import js and css modules (LESS/Sass source files):
|
1
|
["import", { "libraryName": "antd", "style": true }] |
Import js and css modules (css built-in files):
|
1
|
["import", { "libraryName": "antd", "style": "css" }] |
Read More:
- How to Solve MVC Error: Build failed.
- How to Solve Docker ERROR: Service’workspace’ failed to build: ERROR: Service’php-fpm’ failed to build
- How to Solve ImportError: cannot import name gof
- How to Solve Redis Cluster Build Error
- NPM run dev Error Module build failed: Error: Cannot find module ‘node-sass’
- How to Solve Error: Module did not self-register
- Kotlin: How to Solve kapt import error
- How to Solve Windows emacs Build lisp slime error
- How to Solve ModuleNotFoundError: No module named ‘_bz2‘
- How to Solve Error “Could not find com.android.tools.build:gradle:3.0.1”
- How to Solve Echarts Error: import echarts from ‘echarts‘
- Module build failed: Error: Node Sass version 6.0.0 is incompatible with ^4.0.0
- How to Solve Koa Error: Cannot find module ‘koa-router‘
- Webpack Error: Module build failed: TypeError: this.getOptions is not a function
- How to Solve QT Error: The build directory needs to be at the same level as the source directory.
- How to Solve Error: Cannot find module ‘webpack/lib/RequestShortener’
- Celery Error: Did you remember to import the module containing this task?
- Solution: from. Import ft2font importerror: DLL load failed: the specified module cannot be found
- Jenkins uses NPM to build Vue error, and the manual build is normal
- Uncaught SyntaxError: Cannot use import statement outside a module