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 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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Partial Fit with Laravel: The package’s core functionality (asset versioning via fingerprinted filenames and importmap generation) aligns with Laravel’s need for cache-busting and modern JS support. However, its Symfony-centric architecture (e.g., reliance on FrameworkBundle, HttpKernel, and Symfony’s CLI commands) makes direct integration non-trivial.
  • Conflict with Laravel’s Asset Pipeline: Laravel’s default workflow (Vite/Mix) pre-compiles assets into a single file with hashed names, while AssetMapper dynamically maps and digests assets at runtime. This creates duplication (e.g., both systems generating hashed filenames) or conflicts (e.g., Mix’s mix-manifest.json vs. AssetMapper's dynamic mapping).
  • Lack of Laravel-Native Integrations: No built-in support for Laravel’s:
    • Blade directives (e.g., @vite(), @mix()).
    • Artisan commands (e.g., mix:version).
    • Service providers or config structures (e.g., config/app.php vs. Symfony’s config/packages/).
  • Opportunity for Hybrid Use Cases: Could bridge Laravel and Symfony components (e.g., Symfony UX, Mercure) where asset handling needs consistency, but requires custom glue code.

Integration Feasibility

  • Medium-High Effort: Requires significant customization to adapt Symfony’s components (e.g., AssetMapperBundle, AssetMapperInterface) into Laravel’s ecosystem. Key challenges:
    • Service Container Integration: Laravel’s IoC container differs from Symfony’s, requiring adapters (e.g., AssetMapper as a Laravel service provider).
    • CLI Command Adaptation: Symfony’s bin/console commands (e.g., asset:map) must be rewritten as Laravel Artisan commands.
    • Public Path Handling: Laravel’s public_path() vs. Symfony’s public/ directory structure needs alignment.
  • Asset Pipeline Conflicts: If using Vite/Mix, AssetMapper would either:
    • Duplicate work (both systems generating hashed filenames).
    • Overwrite assets (if configured to map the same directories).
  • Importmap Compatibility: Laravel’s frontend ecosystem (e.g., Vite’s import.meta.glob) may conflict with AssetMapper's importmap generation.

Technical Risk

  • High Integration Risk:
    • No Laravel-Specific Documentation: All examples assume Symfony, requiring reverse-engineering of Symfony’s AssetMapperBundle.
    • Undocumented Laravel Hacks: Community solutions (e.g., laravel-asset-mapper) are unofficial and may lag behind Symfony updates.
    • PHP Version Dependencies: Requires PHP 8.4+ (Symfony 8.x), which may not align with Laravel’s supported versions (e.g., Laravel 10+ supports PHP 8.2+).
  • Runtime Risks:
    • Performance Overhead: Dynamic asset mapping at runtime (vs. pre-compiled assets) could increase server load for high-traffic apps.
    • Caching Complexity: Fingerprinted filenames may conflict with Laravel’s cache drivers (e.g., Redis, file-based) if not configured carefully.
    • Importmap Pitfalls: Incorrect importmap generation could break ES module resolution in browsers.
  • Maintenance Risk:
    • Symfony-Led Development: Laravel’s ecosystem moves independently; breaking changes in Symfony’s AssetMapper may not be patched for Laravel.
    • Limited Adoption: No dependents in Laravel’s ecosystem (unlike Vite/Mix), indicating low community support.

Key Questions for TPM

  1. Why Not Vite/Mix?
    • Does the team explicitly reject build tools (e.g., no Webpack/Vite expertise)?
    • Are there specific constraints (e.g., no Node.js, minimal build steps)?
  2. Asset Pipeline Strategy:
    • Will this replace all asset handling (conflicting with Vite/Mix) or supplement it (e.g., for non-JS assets)?
    • How will hashed filenames from AssetMapper interact with Laravel’s cache tags or CDN invalidation?
  3. Team Familiarity:
    • Is the team comfortable with Symfony’s patterns (e.g., bundles, FrameworkBundle)?
    • Are developers willing to maintain custom Laravel-Symfony integration layers?
  4. Performance Impact:
    • What’s the expected asset volume? Dynamic mapping may slow down large directories.
    • How will importmap generation scale with concurrent requests (see jsdelivr flooding bug)?
  5. Long-Term Viability:
    • Is the team open to migrating to Vite/Mix later, or is this a permanent choice?
    • How will this interact with future Laravel features (e.g., built-in ES module support)?
  6. Alternatives Assessment:

Integration Approach

Stack Fit

  • Target Use Case: Laravel projects without Vite/Mix that need:
    • Static asset versioning (CSS/JS/images) with fingerprinted filenames.
    • Importmap support for ES modules (React/Vue/Svelte) without a build pipeline.
  • Incompatible Use Cases:
    • Projects using Laravel Vite/Mix (conflicts with pre-compiled assets).
    • Apps requiring dynamic asset generation (e.g., theme-based assets, SVG sprites).
    • Teams needing hot-reloading, source maps, or advanced bundling.
  • Hybrid Potential:
    • Could complement Symfony components in Laravel (e.g., Symfony UX, Mercure) where asset handling needs consistency.
    • Might serve as a fallback for non-critical features where build tools are overkill.

Migration Path

Step Action Complexity Laravel-Specific Notes
1 Assess Current Asset Workflow Low Document existing asset pipeline (e.g., manual hashing, no build tools).
2 Choose Integration Scope Medium Decide if replacing all asset handling or supplementing it (e.g., for static assets only).
3 Set Up Symfony Compatibility Layer High Create a Laravel service provider to bridge Symfony’s AssetMapper with Laravel’s container. Example:
```php
// app/Providers/AssetMapperServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\AssetMapper\AssetMapper;
use Symfony\Component\AssetMapper\AssetMapperInterface;
class AssetMapperServiceProvider extends ServiceProvider {
public function register() {
    $this->app->singleton(AssetMapperInterface::class, function ($app) {
        $mapper = new AssetMapper();
        // Configure mappings (adapt Symfony’s config to Laravel paths)
        $mapper->map('js', [$app->publicPath('js')]);
        $mapper->map('css', [$app->publicPath('css')]);
        return $mapper;
    });
}

} | Requires reverse-engineering Symfony’s `AssetMapperBundle`. | | 4 | **Adapt CLI Commands** | High | Rewrite Symfony’s `asset:map` command as a Laravel Artisan command. Example: | | |php // app/Console/Commands/MapAssets.php namespace App\Console\Commands; use Illuminate\Console\Command; use Symfony\Component\AssetMapper\AssetMapperInterface; class MapAssets extends Command { protected $signature = 'asset:map'; protected $description = 'Map assets to public directory with fingerprinted filenames'; public function handle(AssetMapperInterface $mapper) { $mapper->dump(); $this->info('Assets mapped successfully!'); } }

| 5 | **Configure Importmap** | Medium | Set up importmap generation in `config/app.php` or a custom config file. Example: |
|  | ```php
// config/asset_mapper.php
return [
    'public_directory' => public_path('build'),
    'importmap' => [
        'includes' => [
            'react' => 'https://esm.sh/react',
            'lodash' => 'https://esm.sh/lodash',
        ],
        'scopes' => [
            '/' => ['app.js'],
        ],
    ],
];
``` | No native Laravel support; requires manual integration. |
| 6 | **Update Asset References** | Low | Replace manual asset paths (e.g., `<script src="app.js">`) with `AssetMapper`-generated paths. Example: |
|  | ```php
// Use a custom Blade directive or helper
{{ asset('app.js') }} // Laravel’s default (no has
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4