just-boris just-boris - 29 days ago 7
Javascript Question

Npm postinstall only on development

I have npm module with following package.json

{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"prepublish": "bower install",
"build": "gulp"
},
"dependencies": {
"express": "~4.0.0",
"body-parser": "~1.0.1"
},
"devDependencies": {
"gulp": "~3.6.0",
"bower": "~1.3.2"
}
}


When I deploy my app to production I don't want install devDependecies so, I run
npm install --production
. But in this case
prepublish
script are called, but it doesn't need, because I use CDN links in production.

How to call postinstall script only after
npm install
but not after
npm install --production
?

Answer

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 ] && bower install"
  }
}