Laravel Vite and Vue

The starter kit already runs Vite. The pieces people break are the @ alias, a secret in a VITE_ variable, and a public/hot file left on the server.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-vite-vue.md
The starter kit already runs Vite. The pieces people break are the @ alias, a secret in a VITE_ variable, and a public/hot file left on the server.
Do not remove laravel(), Vue, Tailwind, or Wayfinder while you add the alias.
Show the diff. Do not commit.

Next: Keep the Vue layout between Inertia visits

On this page · 8 sections
  1. Dev and build
  2. The @ alias
  3. What VITE_ exposes
  4. Where this stops
  5. Recap
  6. FAQ
  7. Next steps
  8. Sources

The starter kit’s Vite setup works on day one. Then someone adds an alias and deletes a plugin, someone else puts a secret in a VITE_ variable, and production loads JavaScript from a laptop. Here are the three edits that go wrong, and the fix for each.

TL;DR

  • npm run dev writes public/hot; npm run build writes public/build. Never deploy public/hot.
  • @ points at resources/js. Add the alias beside the kit’s plugins; don’t replace them.
  • Every VITE_ variable is public. Secrets stay in Laravel’s .env, read on the server.
  • Restart npm run dev (or rebuild) after changing .env.

What you'll learn

  • What public/hot does and why it must not reach production
  • How to restore the @ alias without losing plugins
  • Which VITE_ variables are safe in the browser

Who it's for: Laravel + Vue developers on the starter kit

Applies to: Laravel 13 · Vue starter kit · Vite 8 · laravel-vite-plugin

laravel new with the Vue starter kit already wires Vite, the Vue plugin, and the Laravel plugin. You do not replace vite.config.ts to “add Vue”. This page is the three edits that go wrong after that: imports, environment variables, and the dev server file.

Production builds are the deploy guide. Sail’s HMR host is Sail. The app those assets belong to is Inertia, a SPA, or Nuxt.

Dev and build#

CommandWritesBrowser loads assets from
npm run devpublic/hotThe Vite dev server (your machine)
npm run buildpublic/buildYour Laravel app

npm run dev writes public/hot and serves assets from the Vite process. Laravel reads that file and points the browser at the dev server. That is what you want on your machine.

npm run build writes public/build and removes the need for public/hot.

Gotcha: public/hot on the server

If public/hot is on the server, every page loads JavaScript from the URL in that file, which is your laptop. Delete it. Do not commit it. The deploy guide is the checklist around that file.

Restart npm run dev after .env changes. Vite reads VITE_* at startup and inlines them at build time. A key you add later is not in the bundle until you build again.

Check before you deploy

bash
git ls-files public/hot && echo "remove public/hot from git" || echo "ok"

The @ alias#

The kit aliases @ to resources/js. If a fresh config lost it, put it back beside the plugins. Do not remove laravel(), Vue, Tailwind, or Wayfinder while you add the alias.

vite.config.tstypescript
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";

export default defineConfig({
  // plugins: keep the kit's laravel(), vue(), tailwindcss(), and wayfinder()
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./resources/js", import.meta.url)),
    },
  },
});

Breaks when files move, then Same path everywhere:

resources/js/pages/posts/Edit.vuetypescript
import PostForm from "../../pages/posts/Form.vue";
resources/js/pages/posts/Edit.vuetypescript
import PostForm from "@/pages/posts/Form.vue";

A relative ../../pages/posts/Form.vue works until a file moves. The alias is the path the rest of the kit already uses, including Wayfinder imports under @/actions.

What VITE_ exposes#

Only variables whose names start with VITE_ are available as import.meta.env.VITE_.... That is a browser bundle. Anyone who can load the JavaScript can read them.

resources/js/echo.tstypescript
const key = import.meta.env.VITE_REVERB_APP_KEY;
Safe as VITE_ (public)Never VITE_ (secret)
Reverb app key, host and portDatabase password
The Laravel originGitHub client secret
App nameMail password, API secrets

Heads up: a VITE_ prefix publishes it

A Reverb app key is public by design. A database password, a GitHub client secret, or a mail password is not. Those stay in Laravel’s .env and are read with env() or config() on the server. Prefixing a secret with VITE_ so a Vue page can “just use it” publishes the secret.

The Laravel origin, the Reverb host, and the Reverb port are the usual public values. Set them before npm run build. The Reverb guide is why the key has to be in the bundle at all.

Where this stops#

Vite does not authenticate the API. Cookie setup for a separate dev server on port 5173 is CORS and Sanctum. Same-origin Inertia, opened through the Laravel URL, does not need that CORS file.

Recap#

  • public/hot is for your machine only; production uses public/build.
  • Restore @ beside the kit’s plugins, never instead of them.
  • VITE_ variables ship to every visitor; secrets stay server-side.
  • Restart or rebuild after .env changes.

FAQ#

Why does my production Laravel site try to load assets from localhost:5173?

A public/hot file was deployed. Delete it; with it present, Laravel points the browser at the dev server URL inside it.

Why is my new VITE_ variable undefined?

Vite reads VITE_* variables at startup and inlines them at build time. Restart npm run dev, or run npm run build again.

Can I put an API secret in a VITE_ variable?

No. Anything prefixed VITE_ ends up in the JavaScript bundle that every visitor downloads. Keep secrets in Laravel config.

Next steps#

Sources#

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.