Is there a way to only run npm scripts for installed packages (opposite of --ignore-scripts)

316 views Asked by At

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 postinstall for installed node_modules only?
1

There are 1 answers

0
Ryan Wheale On

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-scripts and --no-bin-links option. This prevents any packages from building/compiling or linking any bin files. This is effectively only downloading the node_modules.

npm install --omit=dev --ignore-scripts --no-bin-links

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:

npm rebuild