Reputation: 8977
node_modules
folder within a given build will never be re-used What is the recommended way to centralize / re-use the node_modules
folder between builds given our stack?
npm cache
-- This happens by default, so at least it's not like we're downloading packages from the internet every time. node_modules
to a common directory -- This approach worked (went from minutes to seconds) but unfortunately some gulp/grunt tasks fail when dealing with symlinks on Windows. Womp womp.node_modules
folder further up the hierarchy: Not sure, but it seems like node may hierarchically search for the node_modules
folder. In that case, creating a node_modules
folder in a parent directory may solve the issue.NODE_PATH
environment variable -- Not sure if setting this will do something different similar to the point above and provide a common node_modules
folder when one is not found in one of our builds.Move-Item
back & forth between a backup directory: If we have to hack it, it might be worth it to use a backup directory per project ID and use Move-Item
, which should update partition links rather than copying files, at least. That approach is outlined on this blog post. Upvotes: 6
Views: 3019
Reputation: 1102
Have you tried docker cache?
Put your npm install
in Dockerfile, run docker build
FROM node:12
WORKDIR /code
COPY ./package.json ./package-lock.json /code
RUN npm install # skiped when package.json/package-lock.json not changed.
ADD . /code
# do other things
Docker build creates a layer for each command(COPY/ADD/RUN), and use the layer as cache(if nothing changed) when build agagin.
As long as package.json/package-lock.json not changed
docker build
will use cache for
COPY ./package.json ./package-lock.json /code
and
RUN npm install
so you don't need to speed up npm install
, it just skiped.
Upvotes: 0
Reputation: 1054
I'm told you can turn off progress reporting and speed it up significantly: http://biercoff.com/how-to-crazy-easily-speed-up-your-npm-install-speed/
Upvotes: 0
Reputation: 1509
What you have been doing is the best practice in the industry. I dont know if u can make it any better with npm.
have u tried yarn instead https://github.com/yarnpkg/yarn there is a way to use along with docker too https://hackernoon.com/using-yarn-with-docker-c116ad289d56#.8bhk0tkz4
Upvotes: 1