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 Bundle Laravel Package

symfony/assetic-bundle

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation (Legacy Context Only) Since this bundle is deprecated, assume you're maintaining an older Symfony 2.x app. Install via Composer:

    composer require symfony/assetic-bundle
    

    Enable in app/AppKernel.php:

    new Symfony\Bundle\AsseticBundle\AsseticBundle(),
    
  2. Configuration Edit app/config/config.yml:

    assetic:
        assets:
            app_css:
                inputs:
                    - '%kernel.root_dir%/../web/css/app.css'
                filters: [cssrewrite, yui_css]
            app_js:
                inputs:
                    - '%kernel.root_dir%/../web/js/app.js'
                filters: [yui_js]
    
  3. First Use Case Generate assets via CLI:

    php app/console assetic:dump --env=prod
    

    Outputs processed files to web/build/.


Implementation Patterns

Workflow Integration

  1. Asset Management

    • Grouping: Define logical bundles (e.g., admin_css, frontend_js) in config.yml for modularity.
    • Filters: Chain filters (e.g., cssrewrite + yui_css) for optimization. Example:
      filters:
          yui_css:
              jar: '%kernel.root_dir%/../vendor/assets/yuicompressor.jar'
      
  2. Twig Integration Embed assets in templates:

    {% stylesheets
        'css/app.css'
        filter='yui_css'
        output='css/app-%version%.css'
    %}
        <link rel="stylesheet" href="{{ asset_url }}">
    {% endstylesheets %}
    
  3. Versioning Use output parameter to append hashes (e.g., app-%version%.css) for cache busting.

  4. Environment-Specific Builds Override config_prod.yml to enable/disable filters:

    assetic:
        use_controller: false  # Disable runtime processing in prod
    

Debugging & Development

  • Watch Mode: Use assetic:watch to auto-rebuild on file changes:
    php app/console assetic:watch --env=dev
    
  • Dry Runs: Test changes without overwriting:
    php app/console assetic:dump --dry-run
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warning

    • Issue: Bundle is archived; Symfony 4+ uses Webpack Encore.
    • Workaround: Migrate to Encore or use symfony/asset-mapper for modern setups.
  2. Filter Dependencies

    • Issue: Missing JAR files (e.g., yuicompressor.jar) break builds.
    • Fix: Install via:
      composer require yui/yuicompressor
      
  3. Caching Quirks

    • Issue: assetic:dump ignores cache dir if not writable.
    • Fix: Set permissions:
      chmod -R 777 app/cache
      
  4. Twig Syntax Errors

    • Issue: Malformed {% stylesheets %} blocks cause runtime errors.
    • Tip: Validate syntax with:
      php app/console assetic:dump --env=dev --verbose
      

Extension Points

  1. Custom Filters Create a service for custom filters (e.g., MyCustomFilter):

    assetic:
        filters:
            my_custom:
                class: AppBundle\Filter\MyCustomFilter
    
  2. Asset Loading Order Use assetic:dump --env=prod --no-debug to enforce production ordering.

  3. Legacy Asset Pipeline For hybrid setups (Assetic + Webpack), exclude processed files from Assetic:

    assetic:
        assets:
            app_js:
                inputs: ['js/app.js', '!js/webpack-bundle.js']
    

Debugging Tips

  • Log Output: Enable verbose mode:
    php app/console assetic:dump --verbose
    
  • Check Cache: Clear cache before rebuilds:
    php app/console cache:clear
    
  • Symlink Issues: Ensure web/ is symlinked to public/ if using shared hosting.
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