欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

antd按需引入+自定义主题

程序员文章站 2024-03-01 08:48:28
...

1.安装依赖

npm i react-app-rewired customize-cra babel-plugin-import less less-loader

2.修改package.json

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

3.根目录下创建config-overrides.js

// 配置具体的修改规则
const {override, fixBabelImports, addLessLoader} = require("customize-cra");
module.exports = override(
	fixBabelImports("import", {
		libraryName: "antd",
		libraryDirectory: "es",
		style: true
	}),
	addLessLoader({
		lessOptions: {
			javascriptEnabled: true,
			modifyVars: {"@primary-color": "green"}
		}
	})
)

4.备注:不用在组件里亲自引入样式,即:import "antd/dist/antd.css"应该删除

相关标签: reactjs