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

apelaez-link/assetic

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require apelaez/link-assetic
    

    Ensure assetic is installed as a dev dependency (composer require assetic/assetic).

  2. Configuration: Add to config/app.php under providers:

    Apelaez\LinkAssetic\AsseticServiceProvider::class,
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Apelaez\LinkAssetic\AsseticServiceProvider"
    
  3. First Use Case: Replace Assetic\Bundle\AsseticBundle\Asset\AssetManager with the package’s manager in your AppServiceProvider:

    use Apelaez\LinkAssetic\AssetManager;
    
    public function register()
    {
        $this->app->singleton('assetic.asset_manager', function ($app) {
            return new AssetManager($app['path'], $app['files']);
        });
    }
    

Implementation Patterns

Core Workflows

  1. Asset Compilation: Use the package’s AssetManager to compile assets (CSS/JS) via:

    $assetManager = app('assetic.asset_manager');
    $assetManager->dump();
    

    Integrate with Laravel’s Asset facade for dynamic asset URLs:

    {{ asset('css/app.css') }} // Works with compiled assets
    
  2. Custom Filters: Extend the package’s filter system (e.g., for Laravel Mix compatibility):

    $assetManager->getFilter('cssrewrite')->setOption('basePath', public_path());
    
  3. Environment-Specific Config: Use config('assetic') to toggle asset compilation per environment:

    if (app()->environment('production')) {
        $assetManager->dump();
    }
    

Integration Tips

  • Laravel Mix: Disable Mix’s default asset compilation and rely on assetic for production builds.
  • Blade Directives: Use @asset for dynamic asset paths:
    @asset('js/app.js')
    
  • Cache Busting: Leverage assetic’s built-in cache busting:
    $assetManager->setDebug(false); // Disable debug mode in production
    

Gotchas and Tips

Pitfalls

  1. Deprecated Dependencies: The package relies on sanpi/assetic (now deprecated). Ensure compatibility with Laravel’s filesystem and path resolution.

  2. Config Overrides: The package may conflict with symfony/assetic-bundle if both are installed. Uninstall the bundle to avoid conflicts:

    composer remove symfony/assetic-bundle
    
  3. Asset Paths: Hardcoded paths in assetic.yaml may break. Use Laravel’s public_path():

    output: {{ public_path('assets') }}
    

Debugging

  • Logs: Enable debug mode for verbose output:
    $assetManager->setDebug(true);
    
  • Clear Cache: Run php artisan cache:clear and php artisan view:clear if assets fail to compile.

Extension Points

  1. Custom Filters: Register new filters via the AssetManager:

    $assetManager->registerFilter(new \Assetic\Filter\YourCustomFilter());
    
  2. Asset Dumping: Override the dump behavior in a service provider:

    $assetManager->setDumpCallback(function () {
        // Custom logic (e.g., log compilation)
    });
    
  3. Environment Checks: Skip compilation in local environments:

    if (!app()->environment('local')) {
        $assetManager->dump();
    }
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware