-
安装react-app-rewired
npm install react-app-rewired@2.0.2-next.0 babel-plugin-import --save -
扩展webpack的配置
2.1.1 在根目录下创建config-overrides.js文件
const { injectBabelPlugin } = require("react-app-rewired");
module.exports = function override(config, env) {
// antd按需加载
config = injectBabelPlugin(
["import", { libraryName: "antd", libraryDirectory: "es", style: "css" }],
config
);
return config;
};
- 修改package.json 的启动脚本为react-app-rewired启动
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
}
网友评论