通过该方法按需引入antd样式,也可以解决antd与tailwindcss样式冲突的问题

解决方案

使用vite-plugin-imp,对antd的样式文件进行按需引入,思路来自github issue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// vite.config.ts
// 需要安装less, antd的使用的less
export default defineConfig({
plugins: [
vitePluginImp({
libList: [
{
libName: "antd",
style: (name) => `antd/lib/${name}/style/index.css`,
},
],
}),
],
});