React脚手架支持 Antd按需引入 和 装饰器
2020-01-15 本文已影响0人
Sommouns
先按照我的package.json,进行install和修改
{
"babel-plugin-import": "^1.13.0",
"customize-cra": "^0.9.1",
"antd": "^3.26.7",
"react-app-rewired": "^2.0.2-next.0",
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
在根目录创建一个文件config-overrides.js
const { override, fixBabelImports, addDecoratorsLegacy } = require('customize-cra');
module.exports = override(
// antd自动引入
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
// 支持decorator
addDecoratorsLegacy()
);