← 返回
未分类 中文

Tailwind Optimizer

Optimize Tailwind CSS usage — detect unused classes, identify opportunities for @apply extraction, audit responsive design, and reduce bundle size.
优化 Tailwind CSS 使用——检测未使用的类,寻找 @apply 提取机会,审计响应式设计,并减小打包体积。
charlie-morrison charlie-morrison 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 313
下载
💾 0
安装
1
版本
#latest

概述

Tailwind Optimizer

Optimize Tailwind CSS usage by detecting unused utilities, identifying extraction opportunities, auditing responsive design consistency, and reducing CSS bundle size. Analyzes config, class usage patterns, and design system adherence.

Usage

"Optimize my Tailwind CSS setup"
"Find unused Tailwind classes"
"Audit responsive design coverage"
"Check my Tailwind config for issues"

How It Works

1. Configuration Audit

cat tailwind.config.js 2>/dev/null || cat tailwind.config.ts 2>/dev/null
cat postcss.config.js 2>/dev/null

Check:

  • Content paths cover all template files
  • Theme extension vs override (prefer extend)
  • Unused plugins loaded
  • Custom colors/spacing consistency
  • Dark mode strategy (class vs media)
  • Prefix configured for embedding in existing CSS

2. Class Usage Analysis

# Most used utilities
grep -roh 'class[Name]*="[^"]*"\|className={[^}]*}' src/ | sort | uniq -c | sort -rn | head -20
# Find long class strings (extraction candidates)
grep -rn 'class[Name]*="[^"]*"' src/ | awk -F'"' '{print NF-1, length($2), $0}' | sort -rn | head -10

Detect:

  • Classes used only once (potential dead code)
  • Repeated class combinations (extract to @apply or component)
  • Conflicting utilities (e.g., text-red-500 text-blue-500)
  • Arbitrary values that should be in theme config
  • !important overrides indicating specificity issues

3. Design System Adherence

  • Using theme values vs arbitrary values (w-[137px] vs w-36)
  • Consistent spacing scale usage
  • Color palette adherence (no off-brand colors)
  • Typography scale consistency
  • Border radius consistency

4. Responsive Design

  • Mobile-first approach (base styles for mobile, md: for desktop)
  • Missing breakpoints on layout components
  • Inconsistent responsive patterns across pages
  • Hidden elements that should use sr-only for accessibility
  • Container width and padding consistency

5. Bundle Optimization

  • Purge/content configuration catching all files
  • JIT mode enabled (v3+ default)
  • Unnecessary variants enabled
  • Large custom plugins adding unused CSS
  • Component library classes not tree-shaken

6. Extraction Recommendations

When a class combination appears 3+ times:

/* Before: repeated in 5 components */
<button className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 font-medium">

/* After: extracted */
@layer components {
  .btn-primary {
    @apply px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 font-medium;
  }
}

Output

## Tailwind CSS Optimization Report

**Version:** Tailwind 4.0 | **Unique classes:** 847
**CSS output:** 34KB (gzipped: 8KB)

### 🟡 Improvements (5)
1. **12 extraction candidates** — repeated class combos (3+ times)
   Top: `flex items-center gap-2` (23 times) → extract to `.flex-row-center`
2. **34 arbitrary values** could use theme tokens
   `text-[#1a1a1a]` → `text-gray-900` (already in palette)
3. **Missing responsive on 8 layout components** — desktop-only layouts
4. **3 conflicting utilities** — `p-4 px-6` (px overrides p's horizontal)
5. Content config missing `*.mdx` files (MDX pages unstyled)

### ✅ Good Practices
- JIT mode with proper content paths
- Consistent use of theme spacing scale
- Dark mode via class strategy (allows user preference)
- CSS output is small (8KB gzipped)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 02:07 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 197 📥 68,115
ai-agent

Slack Messaging

charlie-morrison
Slack 消息—通过 CLI 和 API 发送消息、管理频道、上传文件、添加反应并自动化团队通知。
★ 0 📥 548
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 79 📥 182,817