1、react按需加载、装饰器配置
使?第三?组件antd
npm install antd --save
1 import React, { Component } from ‘react‘ 2 import Button from ‘antd/lib/button‘ 3 import "antd/dist/antd.css" 4 class App extends Component { 5 render() { 6 return ( 7 <div className="App"> 8 <Button type="primary">Button</Button> 9 </div> 10 ) 11 } 12 } 13 export default App
2、配置按需加载,装饰器
根?录创建config-overrides.js,一定要是根?录创建config-overrides名
npm install react-app-rewired customize-cra babel-plugin-import -D 按需加载
npm install -D @babel/plugin-proposal-decorators 装饰器
如有装饰器错误提示可以参照该博客操作:https://blog.csdn.net/qq_41576643/article/details/107933394
1 const { 2 override, 3 fixBabelImports, 4 addDecoratorsLegacy 5 } = require("customize-cra"); 6 7 module.exports = override( 8 fixBabelImports("import", {//antd按需加载 libraryName: "antd", 9 libraryName: "antd", 10 libraryDirectory: "es", //引入目录 11 style: "css" 12 }), 13 experimentalDecorators(), 14 addDecoratorsLegacy(),//配置装饰器 15 );
原文:https://www.cnblogs.com/nothingness/p/13620129.html