It is normal for the CPU usage to spike up when running npm run watch as it is constantly watching for changes in the files. However, there are a few things that can be done to reduce the CPU usage:
-
Increase the polling interval by running
npm run watch-pollinstead ofnpm run watch. This will reduce the number of times the file system is checked for changes. -
Exclude unnecessary files and directories from being watched by adding them to the
webpack.mix.jsfile. For example, if there are large files or directories that do not need to be watched, they can be excluded using themix.disableNotifications()method. -
Use a more powerful CPU or upgrade the existing one.
Here is an example of how to exclude files and directories from being watched in webpack.mix.js:
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.disableNotifications()
.webpackConfig({
watchOptions: {
ignored: /node_modules/
}
});
In this example, the node_modules directory is excluded from being watched.