I am in a situation where I need to ship node_modules with the rest of my code because the destination machines do not have access to our private network (and our private npm repository).
My problem is that I want to execute everything that happens after npm downloads all the files so that individual packages can build themselves correctly for the target machine. Is there a way to accomplish this? Here are a couple other ways to phrase this question:
- How can I run
npm install, but skip the download step? - How can I run
postinstallfor installed node_modules only?
I finally got it figured it out. There were a couple of important steps to make this happen:
When we get ready to package our code for distribution, we download all of the npm dependencies with the
--ignore-scriptsand--no-bin-linksoption. This prevents any packages from building/compiling or linking any bin files. This is effectively only downloading the node_modules.We then distribute our code to the target machine and run the following command so that any compilations and bin links happen on the target machine: