- How do I install importmap-laravel in a Laravel application?
- Run composer require tonysm/importmap-laravel, then run php artisan importmap:install to publish the config and scaffold the import map definition file and entrypoint. Package auto-discovery registers the service provider, so there is nothing to wire up manually on modern Laravel. After that you add the @importmap directive to your Blade layout and start pinning packages.
- Can I use importmap-laravel without Node.js, Vite, or npm?
- Yes, that is the core promise of the package. Dependencies are declared in PHP, pinned by URL from a CDN such as esm.sh or jspm.io, and rendered into the page as a native import map that browsers resolve directly as ES modules. There is no package.json, no node_modules, and no build step in your deploy pipeline. The only requirements are a browser with import maps support and, optionally, the ability to vendor files into your repo.
- How do I pin a JavaScript dependency with the importmap:pin command?
- Run php artisan importmap:pin to add an entry to your import map definition file, mapping a bare specifier like vue or lodash-es to a CDN URL. Pass the --download flag to fetch and vendor the file into your repository instead of resolving it in the browser at runtime. That definition file becomes the single, reviewable source of truth for frontend dependency versions, which is easy to audit in a pull request.
- How do I load the import map in my Blade views?
- Use the @importmap directive in your layout head, before any module script, and it renders the script type="importmap" block along with your module entrypoint tag. The @importmappreload directive emits preload hints for pinned modules so the browser can fetch them earlier. No middleware, routes, or manual script wrangling is required.
- Which Laravel versions does importmap-laravel support, and is it maintained?
- The package follows standard Laravel conventions with a service provider, publishable config, and Artisan commands, so it fits any Blade-based Laravel app regardless of database, queue, or middleware setup. Check the composer.json constraints on Packagist for the exact Laravel and PHP ranges of the release you install. Also review recent release activity and open issues, since the project is effectively single-maintainer and that bus factor matters for long-lived apps.
- Should I vendor JavaScript dependencies instead of loading them from a CDN?
- Vendoring is often the safer production choice. Using --download pulls the pinned files into your repo, which removes the runtime dependency on esm.sh or jspm.io and gives you stable local paths for SRI hashes and CSP script-src allowlisting. Without vendoring, users' browsers load each module directly from the CDN, which is fine on HTTP/2 with a reliable CDN but adds a third-party dependency you do not control.
- Can I use Vue, React, or Alpine.js with import maps in Laravel?
- Vue and Alpine work well because they ship browser-ready ESM builds that esm.sh or jspm.io can serve, so something like import { createApp } from "vue" resolves natively. React is possible but awkward, since JSX needs a compile step and without a bundler you are limited to precompiled builds or alternative templating. Packages that ship only CJS or UMD builds, or that expect bundler plugins, usually need manual workarounds.
- Is importmap-laravel a good fit for SPAs or TypeScript projects?
- Generally no. Import maps deliberately skip transpilation and bundling, so there is no TypeScript, JSX, tree-shaking, code splitting, or hot module reloading. The package fits Blade-first apps where JavaScript is sprinkles plus a few components, such as Livewire and Alpine stacks, admin panels, internal tools, and marketing sites. If the frontend is the product, use Vite instead.
- How do I handle browser caching and version updates with import maps?
- Import maps do not generate content-hashed filenames, so cache invalidation has to be deliberate. Version changes ride on CDN URL query strings or on vendored file paths, so decide up front how your web server and CDN cache those URLs. Vendoring and bumping paths on each upgrade is the most predictable approach for deploy-time cache behavior.
- What are the alternatives to importmap-laravel, such as Vite or Laravel Mix?
- Laravel Vite, and legacy Mix, are the default alternatives and give you bundling, tree-shaking, HMR, and TypeScript support when you need them. importmap-laravel trades those for zero build steps and no node_modules in the deploy artifact, much like importmap-rails does for Rails. Many teams keep Vite for application frontends and reach for import maps on smaller Blade-first projects or internal tools.