create-react-app支持antd按需导入

30次阅读

共计 480 个字符,预计需要花费 2 分钟才能阅读完成。

按需加载配置
npm install react-app-rewired@2.0.2-next.0 babel-plugin-import –save
在项目根目录下新建 config-overrides.js
const {injectBabelPlugin} = require(“react-app-rewired”);
module.exports = function override(config, env) {
config = injectBabelPlugin(
[
“import”,
{
libraryName: “antd”,
libraryDirectory: “es”,
style: “css”
}
],
config
);
return config;
};

修改 package.json
“scripts”: {
“start”: “react-app-rewired start”,
“build”: “react-app-rewired build”,
“test”: “react-app-rewired test”,
“eject”: “react-app-rewired eject”
}
即可完成 antd 组件按需导入

正文完
 0