Certainly! This behavior is expected with Vite: Vite’s hot module replacement (HMR) and auto-refresh only trigger when frontend source files change (like JS, Vue/React/Blade, or CSS), not when backend PHP code changes. That's why, when editing purely backend logic (controllers, models, routes, etc.), Vite doesn’t know to refresh—it's not designed to watch PHP files.
Here’s what you can do:
1. Use Laravel’s vite-plugin-laravel (Optional)
There are community plugins, like vite-plugin-laravel, which support refreshing the browser when PHP files are modified. Consider using one for your dev environment:
Install the plugin:
npm install vite-plugin-laravel --save-dev
Update your vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'vite-plugin-laravel';
export default defineConfig({
plugins: [
laravel()
],
});
Now, changes in Blade/PHP files will also trigger a reload.
2. Manual Browser Extension ("LiveReload")
Use a browser extension like LiveReload or BrowserSync, which can be configured to watch your PHP files and refresh the browser on changes.
Example with BrowserSync and Laravel Mix:
If you previously worked with Laravel Mix, it offers built-in BrowserSync support, which can be adapted for pure frontend workflows, but it doesn't fit well when exclusively using Vite.
3. Hybrid Approach: Manual Refresh
For many teams, the accepted workflow is to manually refresh the browser after backend changes. This is what most Laravel + Vite projects do, since most backend code doesn’t affect the frontend rendering until the next request.
4. Check For Caching Issues
Sometimes not seeing backend changes reflects caching (Laravel cache, route cache, view cache, etc.).
- Clear Laravel cache:
php artisan cache:clear php artisan config:clear php artisan view:clear php artisan route:clear
This ensures you’re seeing the latest backend changes.
Summary Table
| Change Type | Vite Auto-Refresh? | Solution |
|---|---|---|
| JS/CSS/Blade change | Yes | Vite HMR |
| PHP (backend) change | No | Manual reload, LiveReload, plugin |
Conclusion
You’re not missing config—this is standard with Vite and Laravel.
For auto-refreshing on backend changes, consider vite-plugin-laravel or a LiveReload solution. Otherwise, refresh the browser when updating backend code.
Let me know if you want an example of a full setup with vite-plugin-laravel!