Absolutely, here’s a clear summary and explanation of the solution to the high CPU usage when running npm run dev with the Vue starter kit (as posted on Laracasts):
Solution Summary
The high CPU usage was caused by Vite's file-watching mechanism monitoring too many unnecessary files/directories (like storage, vendor, node_modules), and Wayfinder not restricting its scan scope.
Fix: Explicitly tell Vite’s watcher to ignore those heavy directories/files and configure Wayfinder to only scan relevant paths.
The Solution: Update vite.config.ts
Add the following changes to your vite.config.ts:
import inertia from '@inertiajs/vite';
import { wayfinder } from '@laravel/vite-plugin-wayfinder';
import tailwindcss from '@tailwindcss/vite';
import vue from '@vitejs/plugin-vue';
import laravel from 'laravel-vite-plugin';
import { defineConfig } from 'vite';
export default defineConfig({
server: { // Added to fix high CPU usage
watch: {
// Ignore large directories that don't need hot reloading
ignored: ['**/storage/**', '**/vendor/**', '**/node_modules/**'],
},
},
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.ts'],
refresh: true,
}),
inertia({ ssr: false }),
tailwindcss(),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
wayfinder({
formVariants: true,
// Add patterns to limit file watching for Wayfinder
patterns: ['app/Http/Controllers/**/*.php', 'routes/**/*.php'],
}),
],
});
Explanation
- server.watch.ignored:
Tells Vite not to watch changes understorage/,vendor/, andnode_modules/. These folders change very infrequently and don’t need to trigger hot reloads. - wayfinder.patterns:
Restricts Wayfinder to only watch specific folders (your application controllers and routes), cutting down on file system events and CPU usage.
Result
After these changes, Vite (and the npm run dev process) no longer consume abnormally high CPU resources, resolving the issue with your computer's fan and overall system performance while running the dev server.
If you need more details or run into other anomalies, double-check for other plugins or system-specific factors, but this config will fix the most common watcher-CPU problems with the Laravel+Vite+Wayfinder stack.