A command-line tool that automatically migrates legacy Tailwind CSS height/width utility combinations to the new
size-{n}
utility class where applicable.
This tool scans your project files, finding instances where you've used h-{n}
and w-{n}
together
with the same value (where n is 1-12) and replaces them with the equivalent size-{n}
utility class. Yes, this is
literally all it does.
For example:
<!-- Before -->
<div class="w-6 h-6 text-gray-500">...</div>
<!-- After -->
<div class="size-6 text-gray-500">...</div>
git clone https://github.com/helgesverre/tailwind-size-migrator.git
cd tailwind-size-migrator
# Use defaults (current directory, .html and .blade.php files, vendor and node_modules folders are excluded)
python main.py
# Specify a different directory (default is current directory, which makes sense if you copy the script to your project)
python main.py -p ./src
# Specify custom extensions (for you non-Laravel folks, you know who you are)
python main.py -e .jsx .tsx .html
# Exclude specific directories (instead of the defaults vendor and node_modules)
python main.py -x build dist cache
# Specify path, extensions and exclusions (for the control freaks)
python main.py -p ./src -e .jsx .tsx -x build dist
# Do a dry run to see what would be changed without making changes
python main.py --dry-run
# Get help
python main.py --help
Option | Description |
---|---|
-p , --path |
Directory path to search in (default: current directory) |
-e , --ext |
File extensions to process (default: .html .blade.php) |
-x , --exclude-dirs |
Directories to exclude (default: vendor node_modules) |
--dry-run |
Show which files would be modified without making changes |
Starting Tailwind class replacement...
Search path: /path/to/your/project
File extensions: .html, .blade.php
Excluded directories: vendor, node_modules
Searching for files...
ā Updated: ./resources/views/components/icon.blade.php
- Skipped: ./resources/views/layouts/app.blade.php (no changes needed)
ā Updated: ./resources/views/dashboard.blade.php
Summary:
Files scanned: 3
Files updated: 2
pipx run black main.py