Laravel Vite
Agent Workflow (MANDATORY)
Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:
- fuse-ai-pilot:explore-codebase - Check existing vite.config.js, package.json
- fuse-ai-pilot:research-expert - Verify latest Vite docs via Context7
- mcp__context7__query-docs - Query specific patterns (SSR, Inertia)
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
Vite is Laravel's default frontend build tool. It provides fast HMR in development and optimized builds for production.
| Feature |
Purpose |
| HMR |
Instant updates during development |
| Bundling |
Optimized production assets |
| SSR |
Server-side rendering support |
| Frameworks |
Vue, React, Svelte integration |
Critical Rules
- Always use laravel-vite-plugin - Never raw Vite config
- VITE_ prefix for env vars - Only exposed to frontend
- Use @vite directive - Not manual script tags
- Build before deploy -
npm run build in CI/CD
- Configure HMR for Docker - Set
server.host: '0.0.0.0'
Decision Guide
Stack Selection
Using Tailwind CSS?
├── YES → v4? @tailwindcss/vite plugin
│ v3? PostCSS config
└── NO → Just laravel-vite-plugin
Using JavaScript framework?
├── Vue → @vitejs/plugin-vue
├── React → @vitejs/plugin-react
├── Svelte → @sveltejs/vite-plugin-svelte
└── None → Plain JS/CSS only
SSR Decision
Need SEO/fast first paint?
├── YES → Using Inertia?
│ ├── YES → Inertia SSR
│ └── NO → Consider Inertia or Livewire
└── NO → Client-side only
Reference Guide
Concepts (WHY & Architecture)
| Topic |
Reference |
When to Consult |
| Setup |
setup.md |
Initial configuration |
| Entry Points |
entry-points.md |
Multiple bundles |
| Preprocessors |
preprocessors.md |
Sass, Less, PostCSS |
| Assets |
assets.md |
Images, fonts, static |
| Environment |
environment.md |
VITE_ variables |
| Dev Server |
dev-server.md |
HMR, Docker, HTTPS |
| Build |
build-optimization.md |
Chunks, minification |
| SSR |
ssr.md |
Server-side rendering |
| Inertia |
inertia.md |
SPA without API |
| Frameworks |
frameworks.md |
Vue, React, Svelte |
| Security |
security.md |
CSP nonce |
| Deployment |
deployment.md |
Production, CDN |
Templates (Complete Code)
| Template |
When to Use |
| ViteConfig.js.md |
Standard setup |
| ViteConfigAdvanced.js.md |
Full optimization |
| InertiaSetup.md |
Inertia + Vue/React |
| SSRSetup.md |
SSR configuration |
Quick Reference
Basic Setup
// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
});
Blade Directive
<!DOCTYPE html>
<head>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
Commands
| Command |
Purpose |
npm run dev |
Start dev server |
npm run build |
Production build |
npm run preview |
Preview build |
Best Practices
DO
- Use
refresh: true for Blade HMR
- Configure aliases for clean imports
- Split vendors into separate chunks
- Use
VITE_ prefix for frontend env vars
- Test Docker/Sail config locally
DON'T
- Expose sensitive data via VITE_ vars
- Forget to build before deploying
- Use absolute paths for assets
- Skip source maps in staging
- Ignore chunk size warnings
Laravel 13 Notes
laravel/vite-plugin reste compatible Laravel 13 + Vite 6. Adaptations :
- Le helper
@vite() Blade fonctionne sans changement
- Pour Inertia 2 + React 19 : utiliser le preset
@vitejs/plugin-react v4+
- HMR via WebSocket : Reverb 1.4 et Vite peuvent cohabiter sur des ports distincts en dev
- Build production : ajouter
build.target: 'es2023' pour profiter de PHP 8.3 côté serveur
1---2name: laravel-vite3description: Complete Vite bundling for Laravel - assets, HMR, SSR, frameworks, optimization. Use when configuring frontend build pipeline.4versions:5 laravel: "13.0"6 vite: "6.x"7 php: "8.3"8user-invocable: true9references: references/setup.md, references/entry-points.md, references/preprocessors.md, references/assets.md, references/environment.md, references/dev-server.md, references/build-optimization.md, references/ssr.md, references/inertia.md, references/frameworks.md, references/security.md, references/deployment.md, references/templates/ViteConfig.js.md, references/templates/ViteConfigAdvanced.js.md, references/templates/InertiaSetup.md, references/templates/SSRSetup.md10related-skills: laravel-blade, laravel-livewire, fusecore11metadata:12 source: https://skillmd.com/skills/fusengine/laravel-vite13---1415<objective>16Covers Vite as Laravel's frontend build tool: initial setup and the17laravel-vite-plugin, multiple entry points, CSS preprocessors18(Sass/Less/PostCSS), asset handling, VITE_-prefixed environment variables,19the dev server and HMR (including Docker configuration), build optimization20(chunking, minification), server-side rendering, Inertia integration, JS21framework plugins (Vue/React/Svelte), CSP nonce security, and production22deployment.23</objective>2425# Laravel Vite2627## Agent Workflow (MANDATORY)2829Before ANY implementation, spawn 3 agents in parallel, one `Agent` call each with a `name`:30311. **fuse-ai-pilot:explore-codebase** - Check existing vite.config.js, package.json322. **fuse-ai-pilot:research-expert** - Verify latest Vite docs via Context7333. **mcp__context7__query-docs** - Query specific patterns (SSR, Inertia)3435After implementation, run **fuse-ai-pilot:sniper** for validation.3637---3839## Overview4041Vite is Laravel's default frontend build tool. It provides fast HMR in development and optimized builds for production.4243| Feature | Purpose |44|---------|---------|45| **HMR** | Instant updates during development |46| **Bundling** | Optimized production assets |47| **SSR** | Server-side rendering support |48| **Frameworks** | Vue, React, Svelte integration |4950---5152## Critical Rules53541. **Always use laravel-vite-plugin** - Never raw Vite config552. **VITE_ prefix for env vars** - Only exposed to frontend563. **Use @vite directive** - Not manual script tags574. **Build before deploy** - `npm run build` in CI/CD585. **Configure HMR for Docker** - Set `server.host: '0.0.0.0'`5960---6162## Decision Guide6364### Stack Selection6566```67Using Tailwind CSS?68├── YES → v4? @tailwindcss/vite plugin69│ v3? PostCSS config70└── NO → Just laravel-vite-plugin7172Using JavaScript framework?73├── Vue → @vitejs/plugin-vue74├── React → @vitejs/plugin-react75├── Svelte → @sveltejs/vite-plugin-svelte76└── None → Plain JS/CSS only77```7879### SSR Decision8081```82Need SEO/fast first paint?83├── YES → Using Inertia?84│ ├── YES → Inertia SSR85│ └── NO → Consider Inertia or Livewire86└── NO → Client-side only87```8889---9091## Reference Guide9293### Concepts (WHY & Architecture)9495| Topic | Reference | When to Consult |96|-------|-----------|-----------------|97| **Setup** | [setup.md](references/setup.md) | Initial configuration |98| **Entry Points** | [entry-points.md](references/entry-points.md) | Multiple bundles |99| **Preprocessors** | [preprocessors.md](references/preprocessors.md) | Sass, Less, PostCSS |100| **Assets** | [assets.md](references/assets.md) | Images, fonts, static |101| **Environment** | [environment.md](references/environment.md) | VITE_ variables |102| **Dev Server** | [dev-server.md](references/dev-server.md) | HMR, Docker, HTTPS |103| **Build** | [build-optimization.md](references/build-optimization.md) | Chunks, minification |104| **SSR** | [ssr.md](references/ssr.md) | Server-side rendering |105| **Inertia** | [inertia.md](references/inertia.md) | SPA without API |106| **Frameworks** | [frameworks.md](references/frameworks.md) | Vue, React, Svelte |107| **Security** | [security.md](references/security.md) | CSP nonce |108| **Deployment** | [deployment.md](references/deployment.md) | Production, CDN |109110### Templates (Complete Code)111112| Template | When to Use |113|----------|-------------|114| [ViteConfig.js.md](references/templates/ViteConfig.js.md) | Standard setup |115| [ViteConfigAdvanced.js.md](references/templates/ViteConfigAdvanced.js.md) | Full optimization |116| [InertiaSetup.md](references/templates/InertiaSetup.md) | Inertia + Vue/React |117| [SSRSetup.md](references/templates/SSRSetup.md) | SSR configuration |118119---120121## Quick Reference122123### Basic Setup124125```javascript126// vite.config.js127import { defineConfig } from 'vite';128import laravel from 'laravel-vite-plugin';129130export default defineConfig({131 plugins: [132 laravel({133 input: ['resources/css/app.css', 'resources/js/app.js'],134 refresh: true,135 }),136 ],137});138```139140### Blade Directive141142```blade143<!DOCTYPE html>144<head>145 @vite(['resources/css/app.css', 'resources/js/app.js'])146</head>147```148149### Commands150151| Command | Purpose |152|---------|---------|153| `npm run dev` | Start dev server |154| `npm run build` | Production build |155| `npm run preview` | Preview build |156157---158159## Best Practices160161### DO162- Use `refresh: true` for Blade HMR163- Configure aliases for clean imports164- Split vendors into separate chunks165- Use `VITE_` prefix for frontend env vars166- Test Docker/Sail config locally167168### DON'T169- Expose sensitive data via VITE_ vars170- Forget to build before deploying171- Use absolute paths for assets172- Skip source maps in staging173- Ignore chunk size warnings174175---176177## Laravel 13 Notes178179`laravel/vite-plugin` reste compatible **Laravel 13 + Vite 6**. Adaptations :180181- Le helper `@vite()` Blade fonctionne sans changement182- Pour Inertia 2 + React 19 : utiliser le preset `@vitejs/plugin-react` v4+183- HMR via WebSocket : Reverb 1.4 et Vite peuvent cohabiter sur des ports distincts en dev184- Build production : ajouter `build.target: 'es2023'` pour profiter de PHP 8.3 côté serveur