What is Vite?
Vite is a fast frontend build tool. During development it provides instant hot module replacement (HMR), and for production it generates optimized, versioned assets. Since Laravel 9, Vite is the default frontend build tool, integrated throughlaravel-vite-plugin. The plugin handles:
- Entry point management
- HMR support for the development server
- The
@vite()Blade directive - Asset versioning (cache-busting) for production builds
If you are using a Laravel starter kit such as Laravel Breeze, Vite and Tailwind are already configured. This page explains how to set things up from scratch.
Installation and setup
Check Node
Vite requires Node.js 18 or later and npm. Verify your environment:Install packages
New Laravel projects already includevite and laravel-vite-plugin in package.json. Install dependencies:
Configure vite.config.js
The project root contains avite.config.js file. Specify your entry points — the files Vite uses as the starting points for bundling:
Running the development server
Start Vite’s development server withnpm run dev. Changes to your files are reflected in the browser instantly via HMR:
composer run dev starts both php artisan serve and npm run dev simultaneously.Auto-reload Blade views
Setrefresh: true to reload the browser automatically whenever you save a Blade view or route file:
refresh: true, Vite watches these directories for changes:
resources/views/**app/Livewire/**routes/**lang/**
Production build
Before deploying, runnpm run build. Vite bundles and versions your assets and outputs them to public/build/:
manifest.json maps file names to their hashed versions. The @vite() directive reads this file to load the correct asset.
Loading assets in Blade
Add the@vite() directive to the <head> of your layout:
JavaScript and CSS entry points
JavaScript
resources/js/app.js is the main entry point. Import other modules from here:
CSS
Write global styles inresources/css/app.css:
Multiple entry points
For pages with different asset bundles (for example, an admin panel), define multiple entry points:Tailwind CSS
Tailwind CSS v4 integrates as a Vite plugin:1
Install Tailwind
2
Add the plugin to vite.config.js
3
Import Tailwind in your CSS
Tailwind CSS v4 does not require
tailwind.config.js or postcss.config.js. If you are using Tailwind CSS v3, those files are still needed.Path aliases
laravel-vite-plugin automatically sets up an @ alias pointing to resources/js:
resolve.alias:
Framework-specific configuration
Vue
React
@viteReactRefresh before @vite in your Blade layout:
Static assets
To version images or fonts referenced in Blade templates, specify the directories with theassets option:
Vite::asset():