create-react-app+react-app-rewired引入antd实践

npm install antd --save

npm install babel-plugin-import --save-dev
npm install react-app-rewired customize-cra

  

修改package.json下的

create-react-app+react-app-rewired引入antd实践

 

改成(如下图)

"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-app-rewired eject"
}

create-react-app+react-app-rewired引入antd实践

 

 

 在项目根目录下(和 package.json 同级)新建配置文件 config-overrides.js ,并添加如下内容,这是默认的,

module.exports = function override(config, env) {

// 在这里添加配置

return config;

}

  

如果要接入第三方要这样

const { override, fixBabelImports } = require(‘customize-cra‘);
module.exports = override(
fixBabelImports(‘import‘, {
libraryName: ‘antd‘,
libraryDirectory: ‘es‘,
style: ‘css‘,
}),
);
 

  如果报错了那肯定是看了网上的文章

create-react-app+react-app-rewired引入antd实践

那肯定是没有安装  customize-cra

https://ant.design/docs/react/use-with-create-react-app-cn(把这个页面好好看看)

create-react-app+react-app-rewired引入antd实践

 

 

 

create-react-app+react-app-rewired引入antd实践

上一篇:iOS中的分类(category)和类扩展(extension)


下一篇:How to Create an OCM Response file to Apply a Patch in Silent Mode - opatch silent (文档 ID 966023.1)