Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Asset Mapper Laravel Package

symfony/asset-mapper

Symfony AssetMapper exposes asset directories, copies them to a public folder with digested/versioned filenames, and can generate an importmap so you can use modern JavaScript modules without a build step.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-first, Laravel-adaptable: Designed for Symfony’s FrameworkBundle, requiring Laravel-specific wrappers (e.g., service providers, Blade tweaks) for seamless integration. The package’s asset mapping and importmap generation align with Laravel’s static asset needs but lack native Laravel integrations (e.g., public_path(), mix-manifest.json).
  • Modular but opinionated: Leverages Symfony’s dependency injection and event system, which may introduce complexity in Laravel’s simpler service container. The package’s digested filenames and importmap features are a perfect fit for Laravel’s static asset workflows but require customization for dynamic routes or Blade templates.
  • Build-agnostic: Avoids bundling (no Webpack/Vite), making it ideal for static asset versioning and importmap but incompatible with Laravel Mix’s asset compilation.

Integration Feasibility

  • High for static assets: Directly replaces manual ?v=1.2 versioning with hash-based filenames (e.g., app.[hash].js), reducing frontend bugs and improving caching.
  • Medium for importmap: Enables ES modules without a build step, but requires:
    • Custom Blade directives or JavaScript polyfills to inject the generated importmap.json.
    • Manual configuration of asset paths in Laravel’s public/ directory (Symfony assumes public/ is the root).
  • Low for dynamic assets: No support for runtime-generated assets (e.g., SVG sprites, theme-based CSS), requiring fallback to Laravel’s native solutions.

Technical Risk

  • Dependency conflicts: Symfony’s AssetMapper may clash with Laravel’s service container or event system, requiring custom service providers or monkey-patching.
  • Blade template adjustments: Generated asset paths (e.g., /build/app.[hash].js) may not align with Laravel’s default asset() helper, necessitating custom Blade directives or URL rewrites.
  • Caching quirks: Laravel’s file caching (e.g., config('view.compiled')) might interfere with the package’s runtime asset mapping, requiring cache invalidation strategies.
  • PHP version constraints: Symfony 8.x requires PHP 8.4+, which may block adoption in legacy Laravel projects (e.g., LTS on PHP 8.1).

Key Questions

  1. Laravel Compatibility:
    • How will we handle asset path resolution (e.g., asset('js/app.js') vs. Symfony’s /build/app.[hash].js)?
    • Can we integrate with Laravel’s mix-manifest.json or will we need a custom manifest generator?
  2. Performance Impact:
    • What’s the runtime overhead of digesting filenames and generating importmaps during requests?
    • How will preloading (e.g., <link rel="modulepreload">) interact with Laravel’s asset optimization?
  3. Fallback Strategies:
    • How will we handle failed asset mapping (e.g., missing files, circular imports) without breaking the app?
    • Can we gradually adopt this for non-critical assets (e.g., admin panels) before full migration?
  4. Tooling Integration:
    • Will this conflict with Laravel Forge, Envoyer, or Vapor deployments (e.g., file permissions, caching)?
    • How will Hotwire (Turbo/Stimulus) or Alpine.js handle dynamically loaded importmaps?
  5. Long-Term Maintenance:
    • Who will triage Symfony issues (e.g., bug fixes, deprecations) in a Laravel context?
    • Can we fork or extend the package for Laravel-specific needs (e.g., Blade integration)?

Integration Approach

Stack Fit

  • Best for:
    • Static asset-heavy Laravel apps (e.g., marketing sites, PWAs, admin dashboards).
    • Projects migrating from jQuery to ES modules (React/Vue/Svelte) without adopting a build pipeline.
    • Symfony/Laravel hybrid apps where consistent asset handling is needed.
  • Poor fit:
    • Apps using Laravel Mix/Vite (redundant and may conflict).
    • Projects requiring dynamic asset generation (e.g., SVG sprites, theme-based assets).
    • Teams without Symfony familiarity (configuration assumes Symfony patterns).

Migration Path

  1. Pilot Phase:
    • Non-critical assets first: Start with admin panels or static pages (e.g., /about, /contact).
    • Parallel deployment: Run old and new asset pipelines side-by-side using feature flags or subdomains.
  2. Core Integration:
    • Service Provider: Create a Laravel wrapper to:
      • Register the Symfony AssetMapper as a service.
      • Override Symfony’s public/ assumption with Laravel’s public_path().
    • Blade Directives: Extend Laravel’s asset() helper or add @assetMap directives for importmap injection.
    • Artisan Commands: Expose Symfony’s importmap:require as a Laravel command (e.g., php artisan asset:map).
  3. Full Adoption:
    • Replace manual ?v=1.2 versioning with digested filenames.
    • Migrate ES module imports to use the generated importmap.json.
    • Deprecate legacy asset pipelines (e.g., custom PHP scripts for hashing).

Compatibility

  • Laravel 10/11: High (PHP 8.1+ compatibility, but Symfony 8.x requires PHP 8.4+).
  • Laravel 9: Medium (may require Symfony 7.x, but lacks PHP 8.4 features).
  • Legacy PHP: Low (Symfony 6.x supports PHP 7.4+, but importmap features are newer).
  • Third-Party Packages:
    • Laravel Mix/Vite: Conflict (avoid using both; choose one pipeline).
    • Symfony UX: High compatibility (shared asset handling).
    • Hotwire/Turbo: Manual adaptation (importmap may need dynamic injection).

Sequencing

Step Priority Effort Dependencies
Research High Low None
Service Provider Medium Medium Symfony AssetMapper
Blade Directives High Medium Service Provider
Artisan Commands Low Low Service Provider
Pilot Deployment High High Blade Directives, Service Provider
Full Migration Critical High Pilot Success
Documentation Medium Medium All Integrations

Operational Impact

Maintenance

  • Pros:
    • Reduced manual work: No more ?v=1.2 versioning or custom hashing scripts.
    • Centralized asset management: Single configuration for versioning and importmap.
    • Symfony ecosystem benefits: Leverages active maintenance (Symfony team).
  • Cons:
    • Dual maintenance: Laravel-specific wrappers (service providers, Blade directives) require updates alongside Symfony releases.
    • Debugging complexity: Issues may span Symfony’s asset mapping and Laravel’s routing/Blade.
    • Forking risk: Customizations may diverge from upstream, requiring long-term fork maintenance.

Support

  • Symfony Community: Primary support for core AssetMapper features (importmap, asset mapping).
  • Laravel Community: Limited support; issues may require custom solutions or forks.
  • Internal Resources:
    • Symfony expertise needed for advanced configurations (e.g., custom loaders, preload strategies).
    • Laravel expertise required for integration (Blade, service container, Artisan).
  • Vendor Lock-in: Low (MIT license, open-source), but custom wrappers may create dependency on internal code.

Scaling

  • Performance:
    • Asset mapping: Runtime digestion of filenames adds ~5–10ms per request (negligible for most apps).
    • Importmap generation: Caching importmap.json mitigates overhead; pre-generation (e.g., during deploy) is recommended for high-traffic sites.
    • Concurrent requests: Symfony batches requests to CDNs (e.g., jsDelivr) to avoid flooding.
  • Horizontal Scaling:
    • Stateless design works with load-balanced Laravel setups.
    • CDN compatibility: Digested filenames enable long-term caching (e.g., Cloudflare, Fastly).
  • Database Impact: None (file-system only).

Failure Modes

Scenario Impact Mitigation Strategy
Missing asset files Broken links, JS/CSS failures Fallback to original filenames or 404s
Circular imports in importmap Infinite loops, app hangs Symfony’s SequenceParser (fixed in
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope