tailwind-cleaner
v1.0.27
Published
A tool to replace hex colors with named colors in Tailwind CSS projects
Maintainers
Readme
Tailwind Cleaner
A tool to convert arbitrary values (hex colors, units, etc.) into semantic named values in Tailwind CSS projects.
Table of Contents
Features
- Replaces hex colors and arbitrary values with semantic names in your project files
- Converts numeric values and units (px, rem, etc.) to Tailwind's naming conventions
- Prioritizes existing Tailwind config colors and spacing values
- Uses Color Pizza API for color name matching
- Falls back to color-2-name for local color matching
- Automatically updates your tailwind.config.js with new semantic values
- Maintains consistent naming across your entire project
- Adding prefixes to semantic values to avoid naming conflicts
- [NEW] Supports generating CSS variables for theming (modern Tailwind approach)
Installation
Using npx (recommended)
Run directly with npx:
npx tailwind-cleanerLocal Installation
Install locally instead of global:
npm install tailwind-cleaner --save-dev
# or
npm i -g tailwind-cleanerThen run it using:
npx tailwind-cleanerTailwind CSS v4 Configuration Note
If you're using Tailwind CSS v4 with a tailwind.config.js file, add this at the top of your CSS file:
@config "./path/to/tailwind.config.js";
@import 'tailwindcss';CSS Variables Support (New)
The tool now supports the modern approach of using CSS variables for theming. When prompted, if you choose "Yes" to use CSS variables:
- The tool will generate CSS variables (e.g.,
--primary: 255 0 0;) in your global CSS file (src/globals.css,src/index.css, etc.). - It will update your
tailwind.config.jsto reference these variables (e.g.,primary: 'rgb(var(--primary) / <alpha-value>)').
This allows for easier dynamic theming and is compatible with modern Tailwind practices.
Usage
- Run the tool in your project directory
- It will scan your project files for Tailwind classes and arbitrary values
- The tool will suggest semantic replacements
- Confirm changes to update your files and
tailwind.config.js
How It Works
- Scans your project files for Tailwind classes and arbitrary values
- Matches colors against existing Tailwind config values first
- For new colors, uses Color Pizza API or falls back to color-2-name
- Converts numeric values to Tailwind's spacing scale
- Updates all instances with consistent semantic names
- Adds new values to your Tailwind config
Contributing
Contributions are welcome! Please open an issue or PR on GitHub.
License
MIT
