- What does symfony/asset-mapper do?
- It exposes directories of frontend assets, copies them into a public directory using digested filenames for cache busting, and can dump an importmap so browsers can load ES modules without a bundler. It is a Symfony component rather than a Laravel-specific package, so Laravel use requires wiring it into the framework. It is aimed at simple, build-free asset workflows.
- Can I use symfony/asset-mapper in a Laravel application?
- Yes, you can install it with Composer and bind its services in a Laravel service provider, but it is not an official Laravel package. You will typically add configuration, Artisan commands or wrappers, and Blade helpers yourself. It can coexist with Laravel Vite or Mix while you migrate static assets incrementally.
- How do I install symfony/asset-mapper with Composer?
- Run composer require symfony/asset-mapper and ensure your PHP version satisfies the selected Symfony component constraints. In Laravel, you then register a service provider and publish or create a config file for asset paths and the public output directory. Check the Symfony documentation for the component version that matches your PHP and Laravel versions.
- Does symfony/asset-mapper replace Vite or Laravel Mix?
- No, it is not a full bundler and does not provide tree-shaking, minification, hot module replacement, or advanced JavaScript optimization. It replaces manual cache-busting and can provide importmaps for native ES modules in simple applications. Many teams use it alongside Vite or Mix, or only for static assets such as images, fonts, and CSS.
- How does asset versioning and cache busting work with AssetMapper?
- AssetMapper copies assets to a public directory and renames them with a content hash, so URLs change when file contents change. That lets you set long cache lifetimes without manual ?v= query strings. You reference the generated logical path through the component's URL generator rather than hard-coding the digested filename.
- What is an importmap and when should I use it?
- An importmap is a JSON script that tells the browser how to resolve bare JavaScript module specifiers to actual URLs. AssetMapper can generate it so you can write modern ES modules without Webpack, Vite, or another build step. It is best for simple module graphs; complex apps with many dependencies may still benefit from a bundler.
- Which Laravel and PHP versions are supported by symfony/asset-mapper?
- Support depends on the Symfony component version you install, not on Laravel directly. AssetMapper was introduced in Symfony 6.3 and later versions require PHP 8.1 or 8.2 depending on the major line. Confirm compatibility with your Laravel version's PHP constraint and test the integration in your app before adopting it.
- How do I configure asset directories and the public output path in Laravel?
- You configure source directories and the public target directory through the component's config, typically adapted into config/asset_mapper.php for Laravel. Use Laravel helpers such as public_path() and resource_path() when defining those paths. Keep generated assets in a dedicated public subdirectory so they do not conflict with Vite or Mix output.
- How do I test or deploy AssetMapper assets in CI and production?
- Add a build or deploy step that runs the AssetMapper dump or compile command so digested files and the importmap are generated before traffic arrives. Cache the generated output or run the step only when assets change to reduce deployment time. In staging, verify that URLs resolve, hashes change after edits, and the importmap works under your Content Security Policy.
- What are the alternatives to symfony/asset-mapper for Laravel?
- Laravel Vite is the default modern option and provides bundling, hot reloading, and a mature Laravel integration. Laravel Mix remains available for older projects, and manual ?v= query strings or custom hash helpers work for very small sites. AssetMapper is most compelling when you want build-free ES modules and digested filenames without a JavaScript toolchain.