Skip to content

Instantly share code, notes, and snippets.

@woganmay
Created June 25, 2020 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woganmay/d078a2b3cb2472ec75ef90dff184e533 to your computer and use it in GitHub Desktop.
Save woganmay/d078a2b3cb2472ec75ef90dff184e533 to your computer and use it in GitHub Desktop.
Cache node_modules between envoyer.io deploys
#
# Use cached node_modules for faster frontend compile times
# on envoyer.io
#
# Rationale: If you don't want to set up node_modules caching on
# every server you deploy to, this drop-in deployment hook serves
# a similar purpose. It will symlink every new release to a shared
# node_modules folder, cutting out the installation time.
#
# Create cache folder at project level, outside the release
mkdir {{project}}/node_cache
# Get the latest package.json (or package-lock.json)
cp {{release}}/package.json {{project}}/node_cache/web/package.json
# Install/update dependencies within the node_cache
# Since this is preserved between deploys, it should be faster
(cd {{project}}/node_cache || return; npm update;)
# Have the new release use the cache folder
ln -s {{project}}/node_cache/node_modules {{release}}/node_modules
# Recompile the frontend using the cached path
(cd {{release}} || return; npm run prod; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment