SuperAPI AI 工具集

tailwind-v4-shadcn

前端与建站

查看项目

更新于 10-15 23:31

技能介绍

用途:在 Vite + React 项目中搭建 Tailwind CSS v4 与 shadcn/ui 的生产级组合,使用 @theme inline 模式与 CSS 变量架构。资料标注版本为 tailwindcss@4.1.18、@tailwindcss/vite@4.1.18,状态为生产就绪。

主要能力:提供四步强制架构——在 :root/.dark 定义 CSS 变量(颜色需用 hsl() 包裹)、用 @theme inline 将变量映射为 Tailwind 工具类、在 @layer base 应用基础样式(变量不再包裹 hsl())、实现自动暗色模式;并给出暗色模式 ThemeProvider 与切换组件做法。

使用方式:按顺序执行 pnpm add tailwindcss @tailwindcss/vite、pnpm add -D @types/node tw-animate-css、pnpm dlx shadcn@latest init;若存在 v3 配置则 rm tailwind.config.ts;vite.config.ts 使用 @tailwindcss/vite 插件;components.json 中 tailwind.config 设为空字符串,css 指向 src/index.css。

适用场景:Vite + React 项目、单主题加明暗切换、需要 shadcn/ui 动画与语义色工具类的场景。

限制与注意:多主题或动态主题切换不宜用 @theme inline,应改用 @theme;v4 不再使用 tailwind.config.ts;@apply 在 @layer base/components 中受限,需改用 @utility;@layer base 样式可能被工具层覆盖,可显式声明层顺序或直接在根级定义样式;动画依赖 tw-animate-css 而非 tailwindcss-animate;插件需用 @plugin 指令;v4 默认移除标题、列表、按钮等元素样式,ring 默认宽度由 3px 变为 1px;自动迁移工具可能失败,建议手动迁移。资料未提供收费、价格与平台信息。