Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Blade Tailwind Extract Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Native Integration: The package leverages Laravel's Artisan command system, making it a seamless fit for Laravel-based applications. The service provider pattern ensures clean integration with Laravel's service container.
  • Tailwind CSS Optimization: Directly addresses a critical performance bottleneck in Livewire-heavy applications by reducing payload size via @apply extraction.
  • Bidirectional Workflow: Supports both development (inline Tailwind) and production (extracted CSS) modes, aligning with Laravel's multi-environment workflows.

Integration Feasibility

  • Minimal Setup: Requires only a Composer install and optional config publishing, with no database or complex dependencies.
  • Blade Template Compatibility: Works with all major Blade/Livewire/Alpine.js class patterns (class, wire:class, :class, @class, etc.), ensuring broad applicability.
  • Tailwind-Specific: Assumes Tailwind CSS usage, but the @apply approach is framework-agnostic for the CSS layer.

Technical Risk

  • Breaking Changes: Modifying extracted Blade files manually (e.g., renaming files) could invalidate CSS hashes, requiring full restoration.
  • Reserved Class Restrictions: Hardcoded exclusion of group, peer, and material-symbols-outlined classes may conflict with custom Tailwind utilities.
  • Performance Overhead: The wrap command’s deduplication logic could introduce latency for large codebases during initial setup.
  • CSS Collisions: File-based hashing mitigates but doesn’t eliminate collisions if files are moved/renamed without re-extraction.

Key Questions

  1. Livewire Dependency: Does the application heavily rely on Livewire? If not, the payload reduction benefit may be marginal.
  2. Tailwind Utility Usage: Are group, peer, or custom utility classes used extensively? If yes, the reserved class restrictions could limit adoption.
  3. CI/CD Impact: How will this integrate with existing deployment pipelines? The bidirectional workflow requires explicit extract/restore steps.
  4. Team Adoption: Will developers need training to avoid manual edits to extracted classes (e.g., TW-*)?
  5. Build Process: Does the team use Vite/Laravel Mix? The package generates a standalone CSS file, which may need merging into existing builds.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Perfect fit for Laravel apps using Blade, Livewire, and Tailwind. Complements Laravel’s Artisan CLI and service container.
  • Tailwind CSS: Optimized for Tailwind’s @apply feature, though the @apply approach is CSS-agnostic.
  • Livewire Focus: Primarily benefits Livewire components by reducing wire payloads, but applicable to any Blade template.

Migration Path

  1. Pilot Phase:
    • Install as a dev dependency: composer require dxgx/blade-tailwind-extract --dev.
    • Publish config (optional): php artisan vendor:publish --tag=blade-tailwind-extract-config.
    • Test on a non-critical Livewire component:
      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
      
  2. Gradual Rollout:
    • Use the wrap command to identify and mark class lists in high-traffic components.
    • Extract and commit both Blade and CSS files for each component.
    • Monitor Livewire payload sizes via browser dev tools (Network tab).
  3. Full Adoption:
    • Integrate into CI/CD pipeline:
      • Development: Use restore before editing, extract before commits.
      • Production: Ensure extract runs as part of the build/deploy process.
    • Document the workflow in team runbooks.

Compatibility

  • Blade/Livewire/Alpine: Fully compatible with all supported class patterns (see README).
  • Tailwind Config: No conflicts with Tailwind’s content config or JIT mode.
  • CSS Preprocessors: Works alongside PostCSS/Sass if the generated CSS is merged into existing builds.
  • Reserved Classes: Explicitly skips group, peer, and material-symbols-outlined to avoid breaking Tailwind’s selector logic.

Sequencing

  1. Pre-Extraction:
    • Run php artisan dg:blade-tailwind:wrap to identify and mark class lists.
    • Review the dry-run output to validate wrapper names and deduplication.
  2. Extraction:
    • Run php artisan dg:blade-tailwind:extract on targeted components.
    • Commit both Blade and CSS files to version control.
  3. Post-Extraction:
    • Add the CSS file to your build process (e.g., include in vite.config.js or Laravel Mix).
    • Test Livewire components to confirm payload reduction (check Network tab in DevTools).
  4. Maintenance:
    • Use restore before editing extracted components, then extract afterward.
    • Avoid manual edits to generated classes (e.g., TW-*).

Operational Impact

Maintenance

  • CSS Management:
    • Generated CSS must be committed alongside Blade files to maintain sync.
    • Use .gitignore to exclude the CSS file if it’s auto-generated in builds (but ensure it’s included in the build output).
  • Class Naming:
    • Generated class names (e.g., TW-a40f-card-wrapper) are auto-generated and should not be manually edited.
    • Rename Blade files → restore → re-extract to avoid hash collisions.
  • Configuration:
    • Customize 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.

Support

  • Developer Training:
    • Educate the team on:
      • The wrap → extract → restore workflow.
      • Never editing generated classes (TW-*).
      • Using dry-run to preview changes.
    • Document the process in a team wiki or runbook.
  • Debugging:
    • Common issues:
      • Skipped Patterns: Check warnings for group, peer, or custom reserved classes.
      • Hash Collisions: Restore and re-extract if files are moved/renamed.
      • Syntax Errors: Run php artisan dg:blade-tailwind:extract --dry-run to lint files first.
    • Enable debug mode in config for verbose output:
      'debug' => env('BLADE_TAILWIND_DEBUG', false),
      

Scaling

  • Large Codebases:
    • Use patterns to target specific directories (e.g., php artisan dg:blade-tailwind:wrap ./resources/views/livewire).
    • Leverage --min to ignore small class lists (default: 3).
  • Performance:
    • The wrap command’s deduplication logic may slow down for >1000 files. Test on a staging environment first.
    • Cache wrapper names if the same class lists appear across many files.
  • CI/CD:
    • Add to pipeline:
      # Example GitHub Actions step
      - name: Extract Tailwind classes
        run: php artisan dg:blade-tailwind:extract --yy
      
    • Run restore in pre-commit hooks for development branches.

Failure Modes

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.

Ramp-Up

  • Onboarding Time: ~1–2 hours for developers to understand the workflow.
  • Key Steps:
    1. Install and publish config.
    2. Test the wrap and extract commands on a single component.
    3. Verify payload reduction in DevTools.
    4. Integrate into CI/CD and team workflows.
  • Metrics to Track:
    • Livewire payload size reduction (target: 30–50% for large class lists).
    • Number of extracted classes per component.
    • Developer adoption rate (usage of wrap/extract commands).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log