tailwind-theme-builder by jezweb/claude-skills
npx skills add https://github.com/jezweb/claude-skills --skill tailwind-theme-builder设置一个完全主题化的 Tailwind v4 + shadcn/ui 项目,支持深色模式。生成配置好的 CSS、主题提供者和可用的组件库。
pnpm add tailwindcss @tailwindcss/vite
pnpm add -D @types/node tw-animate-css
pnpm dlx shadcn@latest init
# 如果存在 v3 配置文件则删除
rm -f tailwind.config.ts
复制 assets/vite.config.ts 或添加 Tailwind 插件:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: { alias: { '@': path.resolve(__dirname, './src') } }
})
必须严格按照此顺序执行。跳过步骤会破坏主题。
src/index.css:
@import "tailwindcss";
@import "tw-animate-css";
/* 1. 在根元素定义 CSS 变量(不要在 @layer base 内部) */
:root {
--background: hsl(0 0% 100%);
--foreground: hsl(222.2 84% 4.9%);
--primary: hsl(221.2 83.2% 53.3%);
--primary-foreground: hsl(210 40% 98%);
/* ... 所有语义化令牌 */
}
.dark {
--background: hsl(222.2 84% 4.9%);
--foreground: hsl(210 40% 98%);
--primary: hsl(217.2 91.2% 59.8%);
--primary-foreground: hsl(222.2 47.4% 11.2%);
}
/* 2. 将变量映射到 Tailwind 工具类 */
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
}
/* 3. 应用基础样式(此处不要使用 hsl() 包装) */
@layer base {
body {
background-color: var(--background);
color: var(--foreground);
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
结果: bg-background、text-primary 等自动生效。深色模式通过 .dark 类切换 —— 语义化颜色无需使用 dark: 变体。
将 assets/theme-provider.tsx 复制到你的组件目录,然后包装你的应用:
import { ThemeProvider } from '@/components/theme-provider'
ReactDOM.createRoot(document.getElementById('root')!).render(
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<App />
</ThemeProvider>
)
添加主题切换器:
pnpm dlx shadcn@latest add dropdown-menu
查看 references/dark-mode.md 获取 ModeToggle 组件。
{
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true
}
}
"config": "" 至关重要 —— v4 不使用 tailwind.config.ts。
始终:
:root/.dark 中使用 hsl() 包装颜色@theme inline 映射所有 CSS 变量@tailwindcss/vite 插件(而非 PostCSS)tailwind.config.ts切勿:
:root/.dark 放在 @layer base 内部.dark { @theme { } }(v4 不支持嵌套 @theme)hsl(var(--background))@layer base 类中使用 @apply(改用 @utility)| 症状 | 原因 | 修复方法 |
|---|---|---|
bg-primary 不生效 | 缺少 @theme inline | 添加 @theme inline 块 |
| 颜色全是黑/白 | 双重 hsl() 包装 | 使用 var(--colour) 而非 hsl(var(--colour)) |
| 深色模式不切换 | 缺少 ThemeProvider | 用 <ThemeProvider> 包装应用 |
| 构建失败 | tailwind.config.ts 存在 | 删除该文件 |
| 动画错误 | 使用 tailwindcss-animate | 改为安装 tw-animate-css |
@apply 在自定义类上失败 | v4 破坏性变更 | 使用 @utility 替代 @layer components |
查看 references/common-gotchas.md 获取包含来源的详细错误解释。
从 assets/ 目录复制:
index.css —— 包含所有颜色变量的完整 CSScomponents.json —— shadcn/ui v4 配置vite.config.ts —— Vite + Tailwind 插件theme-provider.tsx —— 深色模式提供者utils.ts —— cn() 工具函数references/common-gotchas.md —— 8 个有 GitHub 来源记录的错误references/dark-mode.md —— 完整的深色模式实现references/architecture.md —— 四步模式的深入解析references/migration-guide.md —— v3 到 v4 迁移指南每周安装量
1.3K
仓库
GitHub 星标
643
首次出现
2026年2月18日
安全审计
安装于
opencode1.2K
gemini-cli1.2K
codex1.1K
github-copilot1.1K
cursor1.1K
kimi-cli1.1K
Set up a fully themed Tailwind v4 + shadcn/ui project with dark mode. Produces configured CSS, theme provider, and working component library.
pnpm add tailwindcss @tailwindcss/vite
pnpm add -D @types/node tw-animate-css
pnpm dlx shadcn@latest init
# Delete v3 config if it exists
rm -f tailwind.config.ts
Copy assets/vite.config.ts or add the Tailwind plugin:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: { alias: { '@': path.resolve(__dirname, './src') } }
})
This exact order is required. Skipping steps breaks the theme.
src/index.css:
@import "tailwindcss";
@import "tw-animate-css";
/* 1. Define CSS variables at root (NOT inside @layer base) */
:root {
--background: hsl(0 0% 100%);
--foreground: hsl(222.2 84% 4.9%);
--primary: hsl(221.2 83.2% 53.3%);
--primary-foreground: hsl(210 40% 98%);
/* ... all semantic tokens */
}
.dark {
--background: hsl(222.2 84% 4.9%);
--foreground: hsl(210 40% 98%);
--primary: hsl(217.2 91.2% 59.8%);
--primary-foreground: hsl(222.2 47.4% 11.2%);
}
/* 2. Map variables to Tailwind utilities */
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
}
/* 3. Apply base styles (NO hsl() wrapper here) */
@layer base {
body {
background-color: var(--background);
color: var(--foreground);
}
}
Result: bg-background, text-primary etc. work automatically. Dark mode switches via .dark class — no dark: variants needed for semantic colours.
Copy assets/theme-provider.tsx to your components directory, then wrap your app:
import { ThemeProvider } from '@/components/theme-provider'
ReactDOM.createRoot(document.getElementById('root')!).render(
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<App />
</ThemeProvider>
)
Add a theme toggle:
pnpm dlx shadcn@latest add dropdown-menu
See references/dark-mode.md for the ModeToggle component.
{
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true
}
}
"config": "" is critical — v4 doesn't use tailwind.config.ts.
Always:
hsl() in :root/.dark@theme inline to map all CSS variables@tailwindcss/vite plugin (NOT PostCSS)tailwind.config.ts if it existsNever:
:root/.dark inside @layer base.dark { @theme { } } (v4 doesn't support nested @theme)hsl(var(--background))@apply with @layer base classes (use @utility instead)| Symptom | Cause | Fix |
|---|---|---|
bg-primary doesn't work | Missing @theme inline | Add @theme inline block |
| Colours all black/white | Double hsl() wrapping | Use var(--colour) not hsl(var(--colour)) |
| Dark mode not switching | Missing ThemeProvider | Wrap app in <ThemeProvider> |
See references/common-gotchas.md for detailed error explanations with sources.
Copy from assets/ directory:
index.css — Complete CSS with all colour variablescomponents.json — shadcn/ui v4 configvite.config.ts — Vite + Tailwind plugintheme-provider.tsx — Dark mode providerutils.ts — cn() utilityreferences/common-gotchas.md — 8 documented errors with GitHub sourcesreferences/dark-mode.md — Complete dark mode implementationreferences/architecture.md — Deep dive into 4-step patternreferences/migration-guide.md — v3 to v4 migrationWeekly Installs
1.3K
Repository
GitHub Stars
643
First Seen
Feb 18, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode1.2K
gemini-cli1.2K
codex1.1K
github-copilot1.1K
cursor1.1K
kimi-cli1.1K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
| Build fails | tailwind.config.ts exists | Delete the file |
| Animation errors | Using tailwindcss-animate | Install tw-animate-css instead |
@apply fails on custom class | v4 breaking change | Use @utility instead of @layer components |