那个啥 babel-plugin-import 到底要咋配置才能按需引入
我按文档这样做的
1 create-react-app创建了一个项目,然后装了antd和babel-plugin-import,然后按文档说的,配置了.babelrc,内容是:
{ "plugins": [ [ "import", { "libraryName": "antd", "style": "css" } ] ] }
然后还是不能按需加载,控制台仍然显示
index.js:8 You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.
package.json 内容如下:
{ "name": "mongodb-pbac-client-react", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.11.9", "@testing-library/react": "^11.2.5", "@testing-library/user-event": "^12.7.1", "antd": "^4.12.3", "react": "^17.0.1", "react-dom": "^17.0.1", "react-scripts": "4.0.2", "web-vitals": "^1.1.0" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "babel-plugin-import": "^1.13.3" } }
只有一个组件,里面引入部分是这样的:
import { Button } from 'antd'; // 只引入这个,有按钮,没有样式,而且 console 显示没有按需加载 // import 'antd/dist/antd.css'; // 引入所有样式 // import Button from 'antd/lib/button'; // import 'antd/lib/button/style/css';
这东西到底怎么玩的,只是要这个简单的功能,网上查到的都很复杂,不知道怎么改