简体   繁体   中英

How to skip rebuild and build for Node.js buildpack

When deploying applications to CloudFoundry via the Node.js buildpack

  • npm rebuild
  • npm install

are executed every time during staging.

Both operations can take a significant amount of time, especially for applications with complex vendored dependency trees.

My applications do not need any native modules and have all their dependencies vendored.

I search a way to to skip the rebuild and install steps completely during staging.


Edit : I am aware of the workarounds possible by manipulating package.json as suggested in this SO answer .

Other parts of the build system depend on manifest being true to the actual requirements of the applications, so this is not possible for me.

From the Cloud Foundry & NodeJS build pack perspective, you cannot skip the build step . It's going to run with Yarn or with NPM, and with NPM it'll either run npm install or npm rebuild .

You have two options:

  • You can vendor your dependencies . If you truly do not have any native dependencies then rebuild will basically be a no-op. If you do have native libraries, which most people do, you can run npm install and cf push from an Ubuntu Trusty VM or docker container where it can build and vendor even the native libraries. Again, when you push this will still run npm rebuild but if everything is vendored it should basically be a no-op.

  • You can fork the NodeJS build pack and change the operations to occur in the order that you want. This would probably require you to edit the supply code here and add a flag or some way to skip the rebuild.

Hope that helps!

You can add --ignore-scripts flag to skip run pre and post install hooks

$ npm install --ignore-scripts

http://blog.npmjs.org/post/141702881055/package-install-scripts-vulnerability

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM