A powerful CLI tool designed to automate the migration of Tailwind CSS classes to newer, more efficient conventions. Modernize your codebase without manual refactoring, improving maintainability and consistency across your project.
As Tailwind CSS evolves, certain class patterns become deprecated or less efficient, requiring developers to manually refactor large codebases—a time-consuming and error-prone process. This tool addresses that challenge by providing automated, rule-based conversion of outdated class usages into their modern equivalents.
Example transformations:
w-4 h-4→size-4(unified sizing)mx-4 my-4→m-4(axis consolidation)bg-red-500 bg-opacity-50→bg-red-500/50(modern opacity syntax)space-x-4 space-y-4on flex containers →gap-4(modern gap usage)
- 🔄 Automated Class Migration: Updates Tailwind CSS classes based on predefined conversion rules
- 🎯 Interactive Mode: Guided selection of conversions with checkbox interface
- 🛡️ Git Integration: Ensures repository is clean before making changes, preventing data loss
- 📁 Flexible Path Targeting: Support for glob patterns to target specific files or directories
- 🏢 Monorepo Friendly: Easily integrate into monorepo setups across multiple packages
- 🔍 Environment Detection: Automatically detects project framework (React, Vue, Svelte, Next.js, etc.)
- 📊 Real-time Progress: Live progress reporting with percentage completion
- ⚡ Parallel Processing: Efficient file processing for large codebases
The fastest way to get started is using npx for one-time or ad-hoc usage:
npx @yae-tools/tw-migrateThis downloads and runs the latest version without requiring local installation.
For regular use or CI/CD integration:
npm install -g @yae-tools/tw-migrateAfter installation, the command is available system-wide:
tw-migrate -c size -p "src/**/*.tsx"- Node.js: v20.19+, v22.13+, or v23.5+
- Git: Optional but recommended for safety checks
- Tailwind CSS: v2.0+ (see compatibility section for specific requirements)
Run without arguments to enter interactive mode:
npx @yae-tools/tw-migrateThe tool will:
- Display project environment detection
- Prompt you to select conversion types
- Show real-time progress with file-by-file updates
- Provide a summary of changes made
For scripts or CI environments:
# Apply specific conversions
npx @yae-tools/tw-migrate -c size margin -p "src/**/*.{js,jsx,ts,tsx}"
# Multiple conversions with custom path
npx @yae-tools/tw-migrate -c "size,gap,color-opacity" -p "./components/**/*.tsx"# Process only TypeScript React files
npx @yae-tools/tw-migrate -c size -p "src/**/*.{ts,tsx}"
# Process a single file
npx @yae-tools/tw-migrate -c color-opacity -p "components/Button.tsx"
# Process HTML and CSS files
npx @yae-tools/tw-migrate -c gap -p "**/*.{html,css}"# Target specific package
npx @yae-tools/tw-migrate -c size -p "packages/ui/**/*.tsx"
# Process all packages
npx @yae-tools/tw-migrate -c margin padding -p "packages/**/*.{js,jsx,ts,tsx}"
# Workspace-specific targeting
npx @yae-tools/tw-migrate -c "size,gap" -p "apps/web/src/**/*.tsx"# Skip Git checks in CI environment
npx @yae-tools/tw-migrate -c size --ignore-git -p "src/**/*.tsx"
# Preview changes without writing files
npx @yae-tools/tw-migrate -c size --dry-run --diff
# CI check: fail if files would change
npx @yae-tools/tw-migrate -c "size,margin,padding,color-opacity,gap" --check --json --ignore-gitMerges identical w-{value} and h-{value} classes into unified size-{value} classes.
<!-- Before -->
<div class="w-4 h-4 w-full h-full">
<!-- After -->
<div class="size-4 size-full">Requirements: Tailwind CSS v3.4+
Consolidates axis-specific classes when values are identical.
<!-- Before -->
<div class="mx-4 my-4 px-2 py-2">
<!-- After -->
<div class="m-4 p-2">Supported patterns:
mx-{value}+my-{value}→m-{value}px-{value}+py-{value}→p-{value}
Modernizes opacity usage by merging separate color and opacity classes.
<!-- Before -->
<div class="bg-red-500 bg-opacity-50 text-blue-600 text-opacity-75">
<!-- After -->
<div class="bg-red-500/50 text-blue-600/75">Supported prefixes: bg, text, border, ring, divide, placeholder
Converts space-x and space-y to gap when used together on flex or grid containers.
<!-- Before -->
<div class="flex space-x-4 space-y-4">
<!-- After -->
<div class="flex gap-4">Note: Only applies when both space-x and space-y have the same value and container uses flex or grid.
Updates renamed and removed utilities for Tailwind CSS v4 compatibility.
<!-- Before -->
<div class="shadow-sm rounded outline-none ring flex-shrink-0">
<!-- After -->
<div class="shadow-xs rounded-sm outline-hidden ring-3 shrink-0">Supported patterns: renamed shadow/drop-shadow/blur/backdrop-blur/radius utilities, outline-none → outline-hidden, ring → ring-3, flex-shrink-* → shrink-*, flex-grow-* → grow-*, overflow-ellipsis → text-ellipsis, and decoration-* box-decoration replacements.
Updates legacy Tailwind CSS entrypoint directives to the v4 import API.
/* Before */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* After */
@import "tailwindcss";| Flag | Alias | Type | Description | Default |
|---|---|---|---|---|
--conversions |
-c |
string[] |
Conversion types to apply | Interactive prompt |
--path |
-p |
string |
Glob pattern for file targeting | ./**/*.{js,jsx,ts,tsx,html,css,svelte} |
--ignore-git |
boolean |
Skip Git repository checks | false |
|
--exclude |
-e |
string[] |
Glob patterns to exclude | [] |
--config |
string |
Path to config JSON file | auto-detect | |
--dry-run |
boolean |
Preview changes without writing files | false |
|
--diff |
boolean |
Print a diff for changed files | false |
|
--check |
boolean |
Exit with code 1 if files would change | false |
|
--json |
boolean |
Print machine-readable summary | false |
|
--version |
Display version information | |||
--help |
Show help information |
size- Merge w-/h- classes to size-margin- Consolidate margin axis classespadding- Consolidate padding axis classescolor-opacity- Modernize color opacity syntaxgap- Convert space- to gap classesv4-utilities- Rename Tailwind v4 utilities and removed deprecated class namescss-api- Replace v3@tailwindentrypoint directives with the v4@import "tailwindcss"API
Interactive Mode (when stdout is TTY):
- Displays ASCII logo and environment detection
- Prompts for conversion selection if not specified
- Shows real-time progress with file updates
- Provides confirmation dialogs
Non-Interactive Mode (scripts/CI):
- Requires
--conversionsflag - Silent execution with minimal output
- Exits with error if conversions not specified
The tool automatically detects your project environment:
- Framework Detection: React, Vue, Svelte, Next.js, Nuxt.js, Angular
- Tailwind Version: Validates compatibility requirements
- Git Status: Checks for uncommitted changes
- File Types: Adjusts processing based on detected framework
You can store repeatable options in tw-migrate.config.json or .tw-migraterc.json:
{
"path": "src/**/*.{js,jsx,ts,tsx,html,svelte}",
"exclude": ["**/*.test.tsx", "**/dist/**"],
"conversions": ["size", "margin", "padding", "color-opacity", "gap"],
"dryRun": false,
"diff": false,
"check": false,
"ignoreGit": false
}Use a custom location with:
npx @yae-tools/tw-migrate --config ./config/tw-migrate.jsonBy default, the tool prevents execution if uncommitted changes exist:
# Check Git status
git status
# Commit changes before running
git add .
git commit -m "Pre-modernization commit"
# Or override with --ignore-git flag
npx @yae-tools/tw-migrate --ignore-git| Conversion Type | Minimum Version | Notes |
|---|---|---|
size |
v3.4+ | Uses modern size utilities |
margin, padding |
v2.0+ | Basic axis consolidation |
color-opacity |
v2.0+ | Modern opacity syntax |
gap |
v2.0+ | Gap utilities |
| Arbitrary values | v2.2+ | [custom-values] support |
- React:
.js,.jsx,.ts,.tsx - Vue:
.vue,.js,.ts - Svelte:
.svelte - Angular:
.html,.ts - Generic:
.html,.css
- Minimum: Node.js v20.19+, v22.13+, or v23.5+
- Dependencies: All dependencies are bundled for minimal installation overhead
Framework not detected:
# Verify package.json exists in project root
ls package.json
# Check for framework dependencies
cat package.json | grep -E "(react|vue|svelte|next|nuxt|angular)"Tailwind version warnings:
# Check Tailwind version
npm list tailwindcss
# Upgrade if needed
npm install tailwindcss@latestGit repository issues:
# Initialize Git if needed
git init
# Or skip Git checks
npx @yae-tools/tw-migrate --ignore-gitFile permission errors:
# Check file permissions
ls -la src/components/
# Ensure read/write access
chmod 644 src/components/*.tsxFor detailed output, run with verbose logging:
# Preview the exact changes
npx @yae-tools/tw-migrate -c size --dry-run --diff
# Machine-readable output for automation
npx @yae-tools/tw-migrate -c size --check --json --ignore-git# Process only specific directories
npx @yae-tools/tw-migrate -c size -p "src/components/**/*.tsx"
# Multiple pattern matching
npx @yae-tools/tw-migrate -c gap -p "{components,pages}/**/*.{js,ts}"
# Exclude specific files
npx @yae-tools/tw-migrate -c margin -p "src/**/*.tsx" --exclude "**/*.test.tsx"package.json scripts:
{
"scripts": {
"modernize:interactive": "tw-migrate",
"modernize:size": "tw-migrate -c size",
"modernize:all": "tw-migrate -c size,margin,padding,color-opacity,gap",
"modernize:ci": "tw-migrate -c size --ignore-git"
}
}Pre-commit hooks:
# .pre-commit-config.yaml
- repo: local
hooks:
- id: tw-migrate
name: Modernize Tailwind classes
entry: npx @yae-tools/tw-migrate -c size --ignore-git
language: system
files: \.(js|jsx|ts|tsx|html|css|svelte)$- Processing Speed: ~100-500 files/second (depending on file size)
- Memory Usage: Minimal memory footprint with streaming processing
- Parallel Processing: Automatically optimizes for available CPU cores
- Large Codebases: Tested on projects with 10,000+ files
We welcome contributions! Here's how to get started:
# Clone the repository
git clone https://github.com/Yae-Tools/tw-migrate.git
cd tw-migrate
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Test locally
npm run start- Create conversion function in
src/util/ - Add type definitions in
src/types/conversionTypes.ts - Register in
src/conversions.ts - Add comprehensive tests
- Update documentation
When reporting issues, please include:
- Node.js version (
node --version) - Tailwind CSS version
- Sample code that reproduces the issue
- Expected vs actual behavior
This project is licensed under the MIT License - see the LICENSE file for details.
- Tailwind CSS team for the amazing framework
- Contributors and community for feedback and improvements
- Open source libraries that make this tool possible