Laravel Blade Hot Refresh With Vite not working
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel Blade Hot Refresh With Vite Not Working: A Senior Developer Troubleshooting Guide
As a senior developer working with modern Laravel stacks, we rely heavily on tools like Vite to achieve fast development cycles. The promise of "hot refresh"—where changes in your source files instantly reflect in the browser without a full page reload—is incredibly powerful. However, when setting up asset bundling and live reloading with Vite in a fresh Laravel 9 installation, developers frequently encounter silent failures or unexpected behavior.
If you are facing the issue where changing code in welcome.blade.php doesn't trigger a refresh, even though you have configured @vite and refresh: true, don't panic. This is almost always an environmental or caching issue rather than a fundamental flaw in your configuration. Let’s dive into why this happens and how to debug and fix it.
Understanding the Vite/Laravel Interaction
The setup you described—using Laravel, npm install, linking assets via @vite, and configuring vite.config.js with refresh: true—is fundamentally correct for enabling Hot Module Replacement (HMR) in a Vite environment. The failure usually occurs in the communication chain between the file watcher (Vite), the development server, and the browser.
The key is ensuring that the entire ecosystem is running harmoniously. We need to verify three main components: the server process, the file watching mechanism, and the asset linking.
Step 1: Verify the Vite Server Status
The most common oversight is assuming the server is running correctly. Vite needs to be actively monitoring your files in real-time for changes to trigger the hot module replacement.
Action: Ensure you are running the correct command in your terminal. You should typically start the development server using npm run dev (or whatever script is defined in your package.json).
# Run this command in your project root
npm run dev
If this command runs successfully and stays active without throwing errors, Vite is running its watcher process. If you are running a separate PHP server (like php artisan serve), ensure that the Vite watcher is operating independently or correctly integrated into the workflow. For deep dives into framework tooling and best practices like those promoted by the Laravel ecosystem, reviewing official documentation is always beneficial.
Step 2: Inspect the Vite Configuration
Your provided configuration snippet looks correct for enabling HMR:
// 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, // This flag enables HMR capabilities
}),
],
});
The refresh: true setting tells Vite to enable the necessary hooks for hot module replacement. If this is set but nothing happens, the problem shifts from configuration to execution.
Step 3: Check Asset Linking and Browser Caching
Sometimes, stale browser caches can mask a working setup. Furthermore, ensure your Blade file is correctly referencing the compiled assets.
In your main layout file (e.g., resources/views/layouts/app.blade.php), confirm the @vite directive is placed correctly in the <head> section:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel Vite App</title>
{{-- Ensure this directive is present and correct --}}
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<!-- Your content here -->
</body>
</html>
If the above steps are flawless, try clearing your browser cache entirely (Ctrl+Shift+R or Cmd+Shift+R) and restarting the Vite server (npm run dev).
Conclusion: The Takeaway
When hot refresh fails silently in a modern Laravel/Vite setup, the solution is rarely a complex code change; it’s usually a simple execution check. The issue almost always boils down to one of three things:
- The Vite Watcher is not running: Verify
npm run devor equivalent is actively executing in your terminal. - Caching Interference: Clear the browser cache and reload the application.
- Incorrect Linking: Double-check that the
@vitedirective is present and correctly structured in your Blade files.
By systematically checking these environmental factors, you can ensure that your Laravel development workflow remains fast, smooth, and fully leverage the power of modern tooling like Vite. Keep leaning into robust architecture; for more insights on structuring powerful applications, explore resources from laravelcompany.com.