Npm postinstall only on development Npm postinstall only on development javascript javascript

Npm postinstall only on development


Newer npm (& Yarn) versions include support for the prepare script that is run after each install run but only in development mode. Also, the prepublish is deprecated. This should be enough:

{  scripts: {    "prepare": "bower install"  }}

Docs: https://docs.npmjs.com/misc/scripts


I think you cannot choose what scripts are run based on the --production argument. What you can do, however, is supply a script which tests the NODE_ENV variable and only runs bower install if it's not "production".

If you are always in a unix-y environment, you can do it like this:

{   scripts: {    "prepublish": "[ \"$NODE_ENV\" = production ] && exit 0; bower install"  }}


This only works if you're on a unix-like environment:

NPM sets an environment variable to "true" when install is run with --production. To only run the postinstall script if npm install was not run with --production, use the following code.

"postinstall": "if [ -z \"$npm_config_production\" ]; then node_modules/gulp/bin/gulp.js first-run; fi",