Skip to content

Instantly share code, notes, and snippets.

@gemxx
Created August 23, 2019 05:23
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 gemxx/03f33ac48c9463485e9c068c45ef171a to your computer and use it in GitHub Desktop.
Save gemxx/03f33ac48c9463485e9c068c45ef171a to your computer and use it in GitHub Desktop.
npm_install_speedup
##### NPM Install speedup start
PKG_SUM=$(md5sum package.json | cut -d\ -f 1)
TARBALL=node_modules-${PKG_SUM}.tgz
TARBALL_MD5SUM=${TARBALL}.md5sum
CACHE_BASE_DIR=${HOME}/.cache/
CACHE_TARBALL=${CACHE_BASE_DIR}/${TARBALL}
CACHE_TARBALL_MD5SUM=${CACHE_BASE_DIR}/${TARBALL_MD5SUM}
### Check NPM CACHE DIR
[[ ! -e $CACHE_BASE_DIR ]] && mkdir -p $CACHE_BASE_DIR
### COPY CACHE TARBALL -> ./
if [ -f ${CACHE_TARBALL} ]; then
md5sum -c ${TARBALL_MD5SUM} || rm -f ${TARBALL} ${TARBALL_MD5SUM}
cp -f $CACHE_TARBALL ./
cp -f $CACHE_TARBALL_MD5SUM ./
if [ -f ${TARBALL} ]; then
tar zxf ${TARBALL}
fi
fi
npm install
### UPLOAD TARBALL -> NPM CACHE
if [ ! -f ${TARBALL_MD5SUM} ]; then
if [ -d node_modules ]; then
tar zcf ${TARBALL} node_modules
fi
md5sum $TARBALL >${TARBALL_MD5SUM}
cp -f ./${TARBALL} $CACHE_TARBALL
cp -f ./${TARBALL_MD5SUM} $CACHE_TARBALL_MD5SUM
fi
##### NPM Install speedup end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment