boltconcepts/bdev-assetic-bundle
Installation Add the bundle to your Laravel project via Composer:
composer require boltconcepts/bdev-assetic-bundle
Register the bundle in config/app.php under the providers array:
BoltConcepts\BDevAsseticBundle\BDevAsseticBundle::class,
Basic Configuration Publish the default configuration:
php artisan vendor:publish --provider="BoltConcepts\BDevAsseticBundle\BDevAsseticBundle" --tag="config"
Update config/bdev_assetic.php to match your project’s asset pipeline needs.
First Use Case: Asset Dumping
Define an asset in app/Assetic/config.php (or via YAML/JSON):
return [
'bundles' => [
'app' => [
'assets' => [
'css/app.css' => [
'inputs' => ['public/css/style.css'],
'filters' => ['cssrewrite', 'yui_css'],
],
],
],
],
];
Dump assets to disk:
php artisan assetic:dump
Asset Grouping
Organize assets by logical bundles (e.g., admin, frontend) in config/bdev_assetic.php:
'bundles' => [
'admin' => [
'assets' => [
'js/admin.js' => ['inputs' => ['resources/js/admin/*.js']],
],
],
],
Use {{ asset('bundles/admin/js/admin.js') }} in Blade templates.
Environment-Specific Assets
Leverage Symfony’s environment variables (e.g., APP_ENV) to conditionally load assets:
'bundles' => [
'dev' => [
'assets' => ['css/dev-overrides.css' => ['inputs' => ['public/css/dev.css']]],
],
],
Integration with Laravel Mix Use the bundle alongside Laravel Mix for hybrid workflows:
npm run dev).BDevAsseticBundle for runtime processing (e.g., minification in production).use Assetic\Filter\FilterCollection;
use Assetic\Filter\YuiJsFilter;
public function register()
{
$this->app->extend('assetic.filter_collection', function (FilterCollection $collection) {
$collection->add('custom_js', new YuiJsFilter());
return $collection;
});
}
$dynamicAssets = DB::table('assets')->get();
$config = array_merge(config('bdev_assetic'), ['bundles' => ['dynamic' => ['assets' => $dynamicAssets]]]);
Caching Quirks
php artisan cache:clear
php artisan assetic:clear-cache
?v=<timestamp> in asset URLs to bypass cache during development.Dependency Conflicts
symfony/assetic-bundle is installed (this bundle extends it):
composer require symfony/assetic-bundle
BDevAsseticBundle and AsseticBundle.Laravel-Specific Issues
public_path() is correctly set in config/bdev_assetic.php:
'public_path' => public_path(),
asset() helper or {{ asset() }} in Blade, not {{ url() }} for processed assets.config/bdev_assetic.php:
'debug' => env('APP_DEBUG', false),
storage/logs/laravel.log for Assetic filter errors.Custom Asset Dump Command
Extend the default assetic:dump command:
php artisan make:command CustomAsseticDump
Override handle() to add pre/post-processing logic.
Asset Versioning Automate versioning with a custom filter:
use Assetic\Asset\AssetCollection;
$collection = new AssetCollection(['css/app.css']);
$collection->setTargetPath('public/build/app-' . hash('crc32b', file_get_contents('public/css/app.css')) . '.css');
Asset Manifest Generate a JSON manifest of processed assets for SPAs:
$manifest = [];
foreach (config('bdev_assetic.bundles') as $bundle => $config) {
foreach ($config['assets'] as $output => $asset) {
$manifest[$output] = asset($output);
}
}
file_put_contents(public_path('assets.json'), json_encode($manifest));
How can I help you explore Laravel packages today?