innocenzi/laravel-vite
Innocenzi Laravel Vite integrates the Vite frontend build tool with Laravel, offering Blade directives, helpers, config publishing, and hot module replacement for a fast, modern asset pipeline.
@vite directive and the laravel-vite-plugin npm package, so this library is only worth using if you're on an older stack or already depend on its config format.composer require innocenzi/laravel-vite
php artisan vendor:publish # pick the Vite config entry/tag for your version
config/vite.php. This is the source of truth for the package. The important keys are the entrypoint map, the hot file location (public/hot by default), the build directory (public/build), the manifest path, and the dev server URL. Get these aligned with vite.config.js before debugging anything else.// vite.config.js
export default defineConfig({
build: {
manifest: true,
outDir: 'public/build',
rollupOptions: {
input: ['resources/js/app.ts', 'resources/css/app.css'],
},
},
});
<script>/<link> tags with the directive:
@vite(['resources/js/app.ts', 'resources/css/app.css'])
Depending on your config, you may also reference a named entrypoint declared under entrypoints (e.g. @vite('app')).<script src="/js/app.js">. Point the directive at your real entrypoint, run npm run dev, and confirm the page loads modules from the Vite dev server. Then run npm run build and confirm it switches to hashed files from the manifest.rollupOptions.input in Vite, otherwise production builds will miss files that Blade still references.config/vite.php (e.g. 'app' => 'resources/js/app.ts') so Blade templates reference stable names instead of long paths. This also gives you one place to change a path when you split or move bundles.Vite::isRunningHot()) to render dev-only banners, debug toolbars, or React refresh scripts, and to avoid loading them in production.Vite::asset('resources/images/logo.png')) for files that Vite rewrites, instead of asset(); it resolves through the manifest and keeps cache-busting consistent with your JS/CSS.0.0.0.0 and set server.hmr.host in vite.config.js to the host the browser can reach. The hot file contains a URL the browser must be able to hit — not just the container.npm run dev and php artisan serve together (e.g. Composer scripts, concurrently, or a Makefile target). Document it so new contributors don't end up with a stale hot file.npm ci && npm run build before php artisan config:cache and the deploy. Never ship public/hot; delete it on deploy if your pipeline copies the working tree.laravel-vite-plugin plus Laravel's built-in @vite. To migrate: swap the npm plugin, delete config/vite.php, move the entrypoint list into vite.config.js (laravel({ input: [...], refresh: true })), replace any Vite:: calls with the framework equivalents where they exist, and keep the same @vite([...]) syntax in Blade.public/hot is the #1 failure mode. If the dev server crashes or you stop it without cleanup, the file remains and every asset URL points at a dead port. Symptom: blank page with connection-refused errors in the console. Fix: delete public/hot and restart npm run dev.manifest.json. Inspect public/build/manifest.json directly — keys are relative source paths, not URLs.build.outDir in Vite, update build_directory/manifest in config/vite.php to match. They are not derived from each other.php artisan config:cache is safe, but any environment-specific overrides (e.g. dev server URL) must live in env vars read by the config, not in runtime checks.script-src/connect-src for your dev host only.laravel-mix helpers, only one @vite can be registered. Loading both causes confusing "directive not found" or duplicate-injection behavior.public/hot exist and is Vite running? (2) does public/build/manifest.json exist and contain your entrypoint key? (3) do the config paths and Vite outDir agree? (4) can the browser reach the dev server URL? Ninety percent of issues are one of these four.How can I help you explore Laravel packages today?