Speaking of node_modules
folders, this tip by Roel Van Gils came to mind:
Does your Mac becomes slow/unresponsive (fans kicking in etc.) when you `npm install` a huge project with a million tiny dependencies? I learned that adding an empty `.metadata_never_index` in /node_modules *beforehand* will prevent Spotlight from indexing all that crap.
— Roel Van Gils (@roelvangils) April 2, 2019
Hat tip, Roel! But wait dear reader, there’s more …
~
In case you want to retroactively add .metadata_never_index
files to your node_modules
folders, use this command as suggested by @malfaitrobin (a former student of mine):
$ find . -type d -name "node_modules" -exec touch "{}/.metadata_never_index" \;
You might need to reindex Spotlight after this before it takes effect:
$ sudo mdutil -i on /
~
To stay ahead of things, it’d be much better to create this .metadata_never_index
file before running npm install
.
As nor npm install
(issue) nor yarn install
(issue) have the creation of said file integrated, I use a preinstall script that does the job for me.
To enable it, add the line(s) below to your package.json
:
"scripts": {
"preinstall": "mkdir -p ./node_modules && touch ./node_modules/.metadata_never_index"
}
The preinstall script will be run right before npm install
does its thing, ensuring the presence of the .metadata_never_index
file inside ./node_modules
🙂
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.