How to ignore node_modules when running the watcher in Laravel Mix & Nuxt.js

Recently @stidges tweeted a tip that shows how to ignore `node_modules` when running webpack’s watcher.

How to ignore node_modules when running webpack’s watcher in Laravel Mix

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.

How to ignore node_modules when running webpack’s watcher in Nuxt.js

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!

1 thought on “How to ignore node_modules when running the watcher in Laravel Mix & Nuxt.js

  1. 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. ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.