npm install antd
//实现组件的按需加载,安装依赖模块
npm install react-app-rewired customize-cra babel-plugin-import
定义加载配置的js模块:config-overrides.js
const { override, fixBabelImports } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css'
})
)
修改package.json中的文件
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
}
npm start
即可完成按需加载的功能
自定义主题颜色
npm install less less-loader
修改config-override.js文件
const { override, fixBabelImports, addLessLoader } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true
}),
addLessLoader({
javascriptEnabled: true,
modifyVars: {'@primary-color': '#1DA57A'}
})
)
下面有很多颜色按照需求修改为我们需要的颜色
react中使用antd,以及antd的按需加载以及主题颜色换肤
最新推荐文章于 2023-02-09 16:54:44 发布