symfony/asset-mapper
Symfony AssetMapper exposes asset directories and publishes them to a public folder with digested (versioned) filenames. It can also generate an importmap, letting you use modern JavaScript modules without a build step.
styles.css?v=1.2) by automating cache-busted filenames (e.g., styles.[hash].css), reducing frontend bugs and improving performance without requiring a full build pipeline.Adopt this package if:
Avoid this package if:
FrameworkBundle patterns, requiring Laravel-specific workarounds).mix-manifest.json compatibility, or seamless Laravel Mix/Vite integration).*"This package lets us modernize frontend assets with minimal risk. By automatically generating importmaps and versioned filenames, we:
*"AssetMapper addresses two key pain points:
app.[hash].js) to ensure long-term caching and avoid stale assets.import 'app.js') without a build step, simplifying migration from legacy JS to modern frameworks like React or Vue.
Trade-offs:config/packages/) in Laravel, which may need custom Laravel service providers or packages.mix-manifest.json support—developers will need to use asset() manually or build wrappers.
Recommendation: Use this for static assets + importmap in new projects or non-critical features. Avoid if you’re already using Vite/Mix or need dynamic asset generation."**"If you’re tired of manually hashing filenames or configuring importmaps, this package automates it:
composer require symfony/asset-mapper.config/app.php (Symfony-style) or create a Laravel service provider to bridge the gap.php artisan asset:map to generate hashed assets + importmap.json.
Example Configuration:// config/app.php (Laravel workaround)
'asset_mapper' => [
'public_directory' => public_path('build'),
'mappings' => [
'js' => [public_path('js')],
'css' => [public_path('css')],
],
],
Usage in Blade:
<!-- No Blade helpers; use asset() manually -->
<link href="{{ asset('build/styles.[hash].css') }}" rel="stylesheet">
<script type="importmap">
{{ file_get_contents(public_path('build/importmap.json')) }}
</script>
**Limitations**:
- **No Laravel-native helpers**: You’ll need to build wrappers for Blade or use raw `asset()` calls.
- **Conflicts with Vite/Mix**: Choose one pipeline—don’t mix them.
- **Symfony dependencies**: Some features (e.g., `AssetMapperBundle`) may require additional Laravel glue code."*
---
### **For Product Managers**
*"This is a **low-effort upgrade** for teams stuck with:
- Manual asset versioning (e.g., `styles.css?v=1.2`), leading to cache issues.
- No ES module support, blocking adoption of modern frameworks like React or Vue.
**Use case**: Pilot in a **non-critical feature** (e.g., admin panel or marketing site) to test importmap + versioned assets before full rollout. Measure impact on:
- **Developer velocity**: Time saved on manual hashing/configuration.
- **Performance**: Reduced HTTP requests via importmap preloading.
- **Reliability**: Fewer cache-related bugs in production.
**Alternatives**:
- If you need **bundling**, **Vite is still the gold standard**—this package is only for static assets + importmap.
- If you’re using **Symfony**, this integrates natively; for **pure Laravel**, expect some friction."*
How can I help you explore Laravel packages today?