Last active
June 30, 2017 14:08
-
-
Save aripalo/6d659fefc79dee72e8e3 to your computer and use it in GitHub Desktop.
Using webpack and its polling watch feature (via watchpack) can drain CPU which is due to watchpack polling all the npm deps within node_modules folder. This is a quick hack/fix until proper fix is merged & available in watchpack.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Should be used until https://github.com/webpack/watchpack/pull/23 is merged and available in npm | |
# See https://github.com/webpack/watchpack/issues/2#issuecomment-135204573 for more info | |
# Ensure we have npm | |
if ! hash npm 2>/dev/null; then | |
echo 'No NPM installed!' | |
exit 1 | |
fi | |
# npm@3 uses flat tree structure so account for that | |
if npm -v 2>/dev/null | grep -q "^2."; then | |
FILEPATH="node_modules/webpack/node_modules/watchpack/lib/DirectoryWatcher.js" | |
else | |
FILEPATH="node_modules/watchpack/lib/DirectoryWatcher.js" | |
fi | |
INSERTION_POINT_BEFORE="followSymlinks: false," | |
MISSING_OPTION="ignored: /node_modules/," | |
if ! cat ${FILEPATH} 2>/dev/null | grep -q "${MISSING_OPTION}"; then | |
echo 'Fixing webpack watch (polling) slowness with a manual hack. See https://github.com/webpack/watchpack/pull/23 for more info.' | |
sed -i "s|${INSERTION_POINT_BEFORE}|&\n${MISSING_OPTION}|" "${FILEPATH}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Btw, it is useful to add this into npm scripts, if you have
npm run dev
then add this as"predev": "./watchpack-ignore-node-modules.sh"
… or topostinstall
or whatever you prefer.