Recently @stidges tweeted a tip that shows how to ignore `node_modules` when running webpack’s watcher.
Here is the code snippet.
const mix = require('laravel-mix')
mix.webpackConfig({
watchOptions: {
ignored: /node_modules/
}
})
This is a neat trick that optimize your machine’s CPU usage. @stidges claims that it went from 100%+ to less than 3%. Amazing.
When this tweet appeared in my timeline I was working on a Nuxt.js project and I tried to achieve the same thing.
I’ve searched the internets and did not find a clear explanation on how to do this, but after a while I figured it out.
Here’s the code snippet for your `nuxt.config.js`
module.exports = {
mode: 'spa',
watchers: {
webpack: {
ignored: /node_modules/
}
}
}
Here you go. Less CPU used, your machine will thank you!
Thanks @stidges for the tip!
Oh my god, thank you so much. I’m not using Laravel – just running a regular Nuxt app with `npm run dev`. I’ve been listening to my fans spin up for MONTHS before finally finding this fix. 50% CPU -> 5 % CPU. Thank you again. ?