dxgx/blade-tailwind-extract
Laravel package that shrinks Livewire payloads by extracting long Tailwind class strings from Blade/Livewire into short hashed class names and a generated @apply CSS file. Supports class="", @class/->class arrays, dev inject vs prod extract, and collision-safe hashing.
@apply extraction.class, wire:class, :class, @class, etc.), ensuring broad applicability.@apply approach is framework-agnostic for the CSS layer.group, peer, and material-symbols-outlined classes may conflict with custom Tailwind utilities.wrap command’s deduplication logic could introduce latency for large codebases during initial setup.group, peer, or custom utility classes used extensively? If yes, the reserved class restrictions could limit adoption.extract/restore steps.TW-*)?@apply feature, though the @apply approach is CSS-agnostic.composer require dxgx/blade-tailwind-extract --dev.php artisan vendor:publish --tag=blade-tailwind-extract-config.php artisan dg:blade-tailwind:wrap resources/views/livewire/test-component.blade.php
php artisan dg:blade-tailwind:extract resources/views/livewire/test-component.blade.php
wrap command to identify and mark class lists in high-traffic components.restore before editing, extract before commits.extract runs as part of the build/deploy process.content config or JIT mode.group, peer, and material-symbols-outlined to avoid breaking Tailwind’s selector logic.php artisan dg:blade-tailwind:wrap to identify and mark class lists.dry-run output to validate wrapper names and deduplication.php artisan dg:blade-tailwind:extract on targeted components.vite.config.js or Laravel Mix).restore before editing extracted components, then extract afterward.TW-*)..gitignore to exclude the CSS file if it’s auto-generated in builds (but ensure it’s included in the build output).TW-a40f-card-wrapper) are auto-generated and should not be manually edited.config/dg-blade-tailwind-extract.php for:
css_output_path: Where to generate the CSS file.class_prefix: Change from TW if needed (e.g., UT for utility classes).hash_length: Adjust for shorter/longer class names.wrap → extract → restore workflow.TW-*).dry-run to preview changes.group, peer, or custom reserved classes.php artisan dg:blade-tailwind:extract --dry-run to lint files first.'debug' => env('BLADE_TAILWIND_DEBUG', false),
php artisan dg:blade-tailwind:wrap ./resources/views/livewire).--min to ignore small class lists (default: 3).wrap command’s deduplication logic may slow down for >1000 files. Test on a staging environment first.# Example GitHub Actions step
- name: Extract Tailwind classes
run: php artisan dg:blade-tailwind:extract --yy
restore in pre-commit hooks for development branches.| Failure Scenario | Impact | Mitigation |
|---|---|---|
Manual edit to TW-* classes |
Broken CSS/Blade mismatch | Enforce team policy: Never edit generated classes. |
| File renamed without re-extraction | Hash collision or missing classes | Document restore → move → extract workflow. |
Reserved class (group, peer) extracted |
Broken Tailwind selectors | Configurable reserved classes list. |
| PHP syntax errors in Blade files | Extraction fails | Run php -l or --dry-run before extraction. |
| CSS file not committed | Production mismatch | Enforce commit of both Blade and CSS files. |
| Build process ignores CSS file | Stale CSS in production | Include generated CSS in Vite/Laravel Mix. |
wrap and extract commands on a single component.wrap/extract commands).How can I help you explore Laravel packages today?