Unable to vite build for production in Laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Fixing Vite Asset Loading Issues in Laravel Production Builds As a senior developer working with modern PHP stacks like Laravel, we often encounter subtle but frustrating issues when moving from local development to production deployment. One common sticking point involves asset bundling tools like Vite, where the build process seems successful, but the live application still references development server paths instead of the compiled production files. This post dives deep into why this happens in a Laravel + Vite setup and provides a definitive solution to ensure your compiled assets load correctly in production. ## The Problem: Development Leakage in Production Builds You’ve run `npm run build`, and Vite successfully compiles your CSS and JavaScript into the `public/build` directory, generating files like `app.css` and `app.js`. Your Blade template uses the `@vite` directive, which is designed to handle this compilation. However, inspecting the page source reveals that the assets are still being loaded via the Vite development server path (e.g., `http://localhost:5173/...`) instead of the correct static paths from your public folder. This behavior often occurs because the way Vite handles asset loading is optimized for the Hot Module Replacement (HMR) environment during development, and this context sometimes bleeds into production builds if the asset path configuration isn't explicitly set for static serving. ## Understanding the Mechanism: Vite vs. Laravel Assets The core