tailwind-token-consolidation
millionco/skills · Agent Skill
整合、刪除重複或減少globals.css中的自訂CSS屬性和Tailwind v4設計令牌,同時保持相同的視覺效果。
前往安裝 ↓總覽
| 發布者 | |
|---|---|
| 儲存庫 | millionco/skills ↗ |
| 技能資料夾 | tailwind-token-consolidation |
| 星 | 34 |
| 分支 | 2 |
| 附帶檔案 | 1 |
| 授權 | MIT |
| 最近更新 | 2026年6月30日 |
| 連結 | 技能原始碼 ↗ · 儲存庫 ↗ |
Mozgi 檢查
我們在技能檔案中發現的內容。詳細資訊需訂閱。
安裝
技能就是一個含 SKILL.md 的資料夾。選擇你的代理,在專案根目錄的終端機(macOS、Linux 或 Windows 的 Git Bash)執行指令。
把提示貼到 Claude、Codex 或其他助理:它會自行檢查並安裝技能。
Install the “tailwind-token-consolidation” skill from mozgi.io (https://mozgi.io/skills/millionco-tailwind-token-consolidation/) for me. 1. Download the archive: https://mozgi.io/skills/millionco-tailwind-token-consolidation/download If it fails, take the skill folder from the source: https://github.com/millionco/skills/tree/main/skills/tailwind-token-consolidation 2. Read SKILL.md and the other files. Check the skill is safe: no hidden commands, no sending data elsewhere, no scripts doing something other than described. If anything looks suspicious, stop and tell me. 3. Put the “tailwind-token-consolidation” folder into your agent's skills folder: .claude/skills/ for Claude Code, .agents/skills/ for Codex, .cursor/skills/ for Cursor, .gemini/skills/ for Gemini CLI. Inside the project if we are in one, otherwise in the home folder (~/.claude/skills/ etc.). 4. Make sure <skills folder>/tailwind-token-consolidation/SKILL.md exists. 5. Briefly tell me what this skill does and offer to try it on my task. If you cannot do a step yourself, tell me what to click or type.
git clone --depth 1 --branch main https://github.com/millionco/skills.git /tmp/skills mkdir -p .claude/skills cp -r /tmp/skills/skills/tailwind-token-consolidation .claude/skills/tailwind-token-consolidation
重新啟動 Claude Code — 技能就會出現在清單中,手動呼叫:/tailwind-token-consolidation。要套用到所有專案,請放在 ~/.claude/skills。
git clone --depth 1 --branch main https://github.com/millionco/skills.git /tmp/skills mkdir -p .agents/skills cp -r /tmp/skills/skills/tailwind-token-consolidation .agents/skills/tailwind-token-consolidation
Codex 會從目前資料夾往上到儲存庫根目錄,在 .agents/skills 中尋找技能;用 /skills 或 $tailwind-token-consolidation 呼叫。所有專案:~/.agents/skills。
git clone --depth 1 --branch main https://github.com/millionco/skills.git /tmp/skills mkdir -p .cursor/skills cp -r /tmp/skills/skills/tailwind-token-consolidation .cursor/skills/tailwind-token-consolidation
Cursor 啟動時會載入技能;在 Agent 聊天輸入「/」呼叫。Cursor 也會讀取 .claude/skills 與 .agents/skills。所有專案:~/.cursor/skills。
git clone --depth 1 --branch main https://github.com/millionco/skills.git /tmp/skills mkdir -p .gemini/skills cp -r /tmp/skills/skills/tailwind-token-consolidation .gemini/skills/tailwind-token-consolidation
任務符合時,Gemini CLI 會提議啟用技能,由你確認。所有專案:~/.gemini/skills。
安裝前請先檢視 SKILL.md 與相關檔案。點擊檔案即可預覽。
SKILL.md 內容
作者原文 · 唯讀Tailwind Token Consolidation
You are reducing the count of design tokens in a Tailwind v4 globals.css while preserving visual fidelity.
REQUIRED, in order, for every consolidation task:
1. Audit first, edit never-first. Parse globals.css into structured blocks (@theme inline, :root, .dark, every other scoped block). Count tokens. Build a usage map by scanning ALL .ts/.tsx/.css/.mdx files (excluding globals.css) for class names AND var(--...) refs.
2. Compute the LIVE set transitively. A token is live if (a) its suffix appears as a Tailwind class anywhere, OR (b) it is referenced as var(--name) anywhere, OR (c) it is referenced inside another live token's value. Iterate to a fixed point.
3. Scan globals.css's own utility classes too. Any var(--...) inside .X { ... } blocks (outside :root/.dark/@theme inline) is a hard dependency. Tokens demanded by those classes MUST stay.
4. Build a deterministic rename map as data (old_suffix -> new_suffix or DELETE). Apply it to globals.css AND code in a single script. Never hand-edit class names across the codebase.
5. Verify after every pass: run pnpm typecheck, pnpm lint, pnpm format, pnpm build. All must pass before declaring done.
Do not skip any step. A skipped step is a failed task.
The Two Reduction Levers (apply in this order)
| Lever | What it removes | Risk |
|---|---|---|
| 1. Dead deletion | Tokens with zero usage in code + zero intra-globals demand | None — safe |
| 2. Value-similar collapse | Rename --button → --card when values are within ~5% in both light + dark | Small — pick truly-similar values only |
DO NOT inline tokens into Tailwind arbitrary values (px-[17px], text-[16px]/[1.6875rem], shadow-[#000_0px_1px]). Inlining trades named-token clutter for arbitrary-value clutter — same noise, different file. Named tokens carry intent; arbitrary values destroy it. Realistic reduction with these two levers alone is 50–60%, not 70%. If the user asks for a higher number, push back: the right answer is fewer tokens, not the same noise in className strings.
The Eight Bugs You Will Hit (anticipate them)
1. Value precedence bug. When N tokens collapse to one canonical name, first-write-wins from parse order is unpredictable. The result is often the WRONG color (e.g., --danger ends up holding --diagnostics-table-error-border value, which is the pale border tint, not the bright red). Fix: add an explicit CANONICAL_SOURCE override dict mapping new tokens to a specific source token whose value should win.
2. Scoped override bug. .dashboard-page { --text-inline: 14px; } only works because --text-inline is a var()-referenced custom property. Tokens overridden in any scoped block (.dashboard-page, .dark .dashboard-page, etc.) MUST stay as tokens; deleting them silently breaks the scoped override.
3. Intra-globals consumer bug. Utility classes inside globals.css (e.g., .dropdown-menu-highlight { padding: var(--spacing-dropdown-menu-padding); }) read tokens that don't appear in any .tsx file. Deleting these from @theme produces a runtime-undefined CSS var. Fix: strip @theme inline/:root/.dark/etc. blocks from the CSS text before scanning, then collect every var(--X) ref in the remainder. Those tokens MUST stay.
4. Category cross-pollination bug. A suffix can appear in multiple categories. For example, organization-section-surface is a COLOR (white) AND a SHADOW alias prefix (--shadow-organization-section-surface). If your map has both 'organization-section-surface': 'card' (color) and 'organization-section-surface': 'surface-soft' (shadow), the second one will overwrite the bare-token rename in your global map. Fix: only the COLOR category renames the bare --X token. For SHADOW/SPACING/TEXT/RADIUS/FONT/TRACKING, rename ONLY the --<theme-prefix>-X alias, never the bare name.
5. Aggressive icon-color collapse bug. Collapsing every "grey icon" (#696969, #898989, #b3b3b3, #c1c1c1, #dddddd) to a single --icon token makes the originally-light icons look noticeably darker — and on dark surfaces (e.g., dropdown menus that stay dark in both modes), it inverts the intended contrast. Fix: keep TWO icon tones: --icon (~#696969 mid-grey) and --icon-soft (~#b3b3b3 light-grey). Map originally-light icons to --icon-soft.
6. Surface-with-conditional-transparency bug. Some tokens are transparent in one mode and a concrete color in the other (e.g., --repository-card-panel: #ffffff in light, transparent in dark — the dark version is intentionally see-through). Collapsing into --card makes the panel opaque in dark mode, visibly changing the layered look. Fix: if a token's value is transparent in one mode and concrete in the other, do NOT collapse it with an always-opaque token. Either keep it separate or inline the conditional logic in the consuming className.
7. bg-X color/image collision bug. Tailwind v4 resolves bg-X against BOTH --color-X (background-color) and --background-image-X (background-image). If only --background-image-X exists, bg-X paints the gradient correctly. But if you rename some OTHER token (e.g., --install-button-text) to --install-button, you create a --color-install-button alias — and now bg-install-button may set background-color: white on top of the gradient, making the button look empty/invisible. Fix: before collapsing a color suffix to name X, grep for --background-image-X and any bg-X class usage. If either exists, pick a different target name (e.g., keep --install-button-text instead of renaming to --install-button).
8. Always-dark surface bug. Tokens for dropdown menus, tooltips, popovers-that-stay-dark, etc., have text/icon colors that are LIGHT in BOTH light and dark modes (because the surface stays dark regardless of theme). Collapsing --dropdown-menu-text into --foreground makes the dropdown text dark in light mode (dark text on dark surface = invisible). Fix: before collapsing a token, diff its light-mode and dark-mode values. If both values are on the same side of the L=0.5 line (both light or both dark), it lives on an always-light or always-dark surface and CANNOT be collapsed with a flipping token like --foreground or --icon. Keep it as its own token.
The Three-Pass Block Transformation
When emitting a :root or .dark block, write entries in THIS order:
# Pass 1: canonical (non-renamed) entries — these set the source of truth.
for name, value in original_decls.items():
target = TOKEN_RENAME.get(name)
if target is None or target == name:
out[name] = fix_var_refs(value)
# Pass 2: CANONICAL_SOURCE overrides — explicit pick for collapsed groups.
for new_token, source_token in CANONICAL_SOURCE.items():
if source_token in original_decls:
out[new_token] = fix_var_refs(original_decls[source_token])
# Pass 3: other renamed entries — only if the target isn't already set.
for name, value in original_decls.items():
target = TOKEN_RENAME.get(name)
if target and target != name and target not in out:
out[target] = fix_var_refs(value)
This guarantees: (a) the canonical token's original value always wins over a rename, (b) you explicitly control which source provides the value for NEW tokens like --danger, and (c) duplicate entries never appear in the output.
Apply-And-Verify Loop
Run this loop after EVERY rename-map change:
git checkout -- apps/web # always start from a clean tree
python3 /tmp/transform.py # apply the rename + inline map
pnpm typecheck && pnpm lint && pnpm format && pnpm --filter web build
If any check fails, fix the map (not the generated output), then re-run. Hand-editing the generated globals.css is a footgun: the next transformation run will overwrite your fix.
Rationalization Table
| You will think | Don't |
|---|---|
| "I'll just delete this token, no one uses it" — without searching globals.css's own classes | Strip the @theme/:root/.dark blocks and search the remainder for var(--X) first |
| "These two greys are basically the same" — without checking BOTH light and dark mode values | Diff both modes. A value that's close in light can diverge in dark |
| "I'll inline single-use tokens into arbitrary values for extra reduction" | That's just relocating the noise. Keep named tokens; inlining is anti-consolidation |
| "User asked for 70% — I should hit it even if I have to inline" | Push back. 50–60% with named tokens beats 70% with arbitrary values. Report the honest number |
| "I'll fix the broken class manually after the script runs" | The next script run will revert your edit. Fix the script, not the artifact |
| "First-write-wins is fine, parse order is deterministic" | Until someone reorders :root. Use explicit CANONICAL_SOURCE overrides |
| "This rename target name is fine, no collisions" — but there's already a --background-image-<name> | Grep for --background-image-<target> and bg-<target> usage before picking the target name |
Before Declaring Done
You MUST have:
1. Run pnpm typecheck — exit 0.
2. Run pnpm lint — 0 errors, 0 warnings.
3. Run pnpm format — completed.
4. Run pnpm --filter web build — exit 0.
5. Counted final tokens with rg "^\s*--[a-z][a-zA-Z0-9-]*\s*:" apps/web/app/globals.css -o | sort -u | wc -l. Report before/after counts and the percentage reduction.
6. Confirmed at least the top 3 visible surfaces (cards, page background, dropdowns) render with the intended colors by reading the resulting :root block end-to-end and verifying canonical values match what you expected.
A green build with broken visual output is a failed task. A counted reduction without verification is a failed task.
常見問題
tailwind-token-consolidation 技能有什麼用途?
整合、刪除重複或減少globals.css中的自訂CSS屬性和Tailwind v4設計令牌,同時保持相同的視覺效果。
如何安裝 tailwind-token-consolidation?
打開本頁的「安裝」區塊並選擇你的代理 — Claude Code、Codex、Cursor 或 Gemini CLI:那裡有把技能資料夾複製到正確位置的現成指令。也可以複製「透過助理」分頁中的提示,讓助理自行檢查並安裝技能。
tailwind-token-consolidation 適用哪些 AI 模型?
技能是純 Markdown 指示(Agent Skills 格式),因此 tailwind-token-consolidation 適用任何讀取 SKILL.md 的代理:Claude Code、Codex、Cursor、Gemini CLI、GitHub Copilot、OpenCode 等。只有在任務符合技能描述時,模型才會載入指示。
tailwind-token-consolidation 是免費的嗎?
此技能由 millionco 公開發布,採用 MIT 授權。技能本身免費 — 你只需向 AI 供應商支付實際使用的 token 費用。
安裝技能安全嗎?
技能是代理會遵循的指示,安裝前請閱讀 SKILL.md 及相關檔案。技能資料夾中的腳本只有在代理執行時才會運行 — 留意它的動作,不要授予多餘權限。
技能和 MCP 伺服器或外掛有何不同?
MCP 伺服器或外掛為模型提供新工具 — 會執行並回傳結果的程式碼。技能提供的是知識與流程:如何處理任務、要遵循哪些步驟、好的成果長什麼樣子。它不需要伺服器或 API 金鑰。