Weave Code
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

Assetic Laravel Package

bonami-cz/assetic

Assetic is a PHP asset management framework for combining, filtering, and dumping assets like JS and CSS. Supports asset collections, file/glob inputs, metadata (target path, mtime), and a wide range of filters for compilation and minification.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require bonami-cz/assetic
    

    Ensure bonami-cz/assetic is listed in composer.json under require.

  2. Basic Setup Add the service provider to config/app.php:

    'providers' => [
        // ...
        Bonami\Assetic\AsseticServiceProvider::class,
    ],
    
  3. First Use Case: Compiling Assets Define a simple asset configuration in config/assetic.php:

    'assets' => [
        'app' => [
            'inputs' => [
                public_path('css/app.css'),
                public_path('js/app.js'),
            ],
            'output' => public_path('build/app.css'),
            'filters' => ['cssrewrite', 'uglifyjs'],
        ],
    ],
    

    Trigger compilation via Artisan:

    php artisan assetic:dump app
    

Implementation Patterns

Workflows

  1. Development vs. Production Use environment-based configurations:

    if (app()->environment('production')) {
        $assetic->setDebug(false);
    }
    
  2. Dynamic Asset Loading Load assets dynamically in Blade:

    @assetic('app', ['output' => 'build/app.css'])
    
  3. Integration with Laravel Mix Use Assetic for PHP-based asset processing while leveraging Mix for JS/CSS bundling:

    $mix->assetic(['app'], public_path('mix-manifest.json'));
    

Integration Tips

  • Custom Filters: Extend Assetic’s filters by creating a custom filter class:

    namespace App\Filters;
    use Assetic\Filter\FilterInterface;
    
    class CustomFilter implements FilterInterface { ... }
    

    Register it in config/assetic.php:

    'filters' => [
        'custom' => App\Filters\CustomFilter::class,
    ],
    
  • Asset Versioning Automatically append version hashes to output files:

    $assetic->setUseCache(true);
    $assetic->setCacheDir(storage_path('app/assetic'));
    

Gotchas and Tips

Pitfalls

  1. Caching Issues Clear Assetic cache when updating filters or inputs:

    php artisan assetic:clear
    
  2. File Permissions Ensure storage_path('app/assetic') is writable:

    chmod -R 775 storage/app/assetic
    
  3. Filter Conflicts Avoid duplicate filters (e.g., cssrewrite + cssrewrite). Validate filters in config/assetic.php.

Debugging

  • Verbose Output Enable debug mode for detailed logs:

    php artisan assetic:dump --debug
    
  • Dry Runs Test configurations without writing files:

    php artisan assetic:dump --dry-run
    

Extension Points

  1. Custom Dump Command Extend the AsseticDumpCommand for project-specific logic:

    namespace App\Console\Commands;
    use Bonami\Assetic\Console\AsseticDumpCommand;
    
    class CustomAsseticDumpCommand extends AsseticDumpCommand {
        protected $name = 'assetic:custom-dump';
        // Override logic here
    }
    
  2. Event Listeners Listen to assetic.dump events for post-processing:

    Event::listen('assetic.dump', function ($event) {
        // Post-process output (e.g., minify further)
    });
    
  3. Asset Manifests Generate JSON manifests for SPAs:

    $manifest = $assetic->getManifest();
    file_put_contents(public_path('mix-manifest.json'), json_encode($manifest));
    
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views