Installation:
composer require apelaez/link-assetic
Ensure assetic is installed as a dev dependency (composer require assetic/assetic).
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"
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']);
});
}
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
Custom Filters: Extend the package’s filter system (e.g., for Laravel Mix compatibility):
$assetManager->getFilter('cssrewrite')->setOption('basePath', public_path());
Environment-Specific Config:
Use config('assetic') to toggle asset compilation per environment:
if (app()->environment('production')) {
$assetManager->dump();
}
assetic for production builds.@asset for dynamic asset paths:
@asset('js/app.js')
assetic’s built-in cache busting:
$assetManager->setDebug(false); // Disable debug mode in production
Deprecated Dependencies:
The package relies on sanpi/assetic (now deprecated). Ensure compatibility with Laravel’s filesystem and path resolution.
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
Asset Paths:
Hardcoded paths in assetic.yaml may break. Use Laravel’s public_path():
output: {{ public_path('assets') }}
$assetManager->setDebug(true);
php artisan cache:clear and php artisan view:clear if assets fail to compile.Custom Filters:
Register new filters via the AssetManager:
$assetManager->registerFilter(new \Assetic\Filter\YourCustomFilter());
Asset Dumping: Override the dump behavior in a service provider:
$assetManager->setDumpCallback(function () {
// Custom logic (e.g., log compilation)
});
Environment Checks: Skip compilation in local environments:
if (!app()->environment('local')) {
$assetManager->dump();
}
How can I help you explore Laravel packages today?