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(),
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]
First Use Case Generate assets via CLI:
php app/console assetic:dump --env=prod
Outputs processed files to web/build/.
Asset Management
admin_css, frontend_js) in config.yml for modularity.cssrewrite + yui_css) for optimization. Example:
filters:
yui_css:
jar: '%kernel.root_dir%/../vendor/assets/yuicompressor.jar'
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 %}
Versioning
Use output parameter to append hashes (e.g., app-%version%.css) for cache busting.
Environment-Specific Builds
Override config_prod.yml to enable/disable filters:
assetic:
use_controller: false # Disable runtime processing in prod
assetic:watch to auto-rebuild on file changes:
php app/console assetic:watch --env=dev
php app/console assetic:dump --dry-run
Deprecation Warning
symfony/asset-mapper for modern setups.Filter Dependencies
yuicompressor.jar) break builds.composer require yui/yuicompressor
Caching Quirks
assetic:dump ignores cache dir if not writable.chmod -R 777 app/cache
Twig Syntax Errors
{% stylesheets %} blocks cause runtime errors.php app/console assetic:dump --env=dev --verbose
Custom Filters
Create a service for custom filters (e.g., MyCustomFilter):
assetic:
filters:
my_custom:
class: AppBundle\Filter\MyCustomFilter
Asset Loading Order
Use assetic:dump --env=prod --no-debug to enforce production ordering.
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']
php app/console assetic:dump --verbose
php app/console cache:clear
web/ is symlinked to public/ if using shared hosting.How can I help you explore Laravel packages today?