Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run npm install --production on OpenShift

When I push my code to OpenShift, it looks like it's installing my devDependencies which takes forever. I would really love to set it up so it will only install the dependencies (by running with the --production flag). Is there any way to do this?

like image 895
kentcdodds Avatar asked Dec 21 '13 22:12

kentcdodds


2 Answers

You can tell npm to install using the --production flag by setting the NPM_CONFIG_PRODUCTION environment variable to "true".

Here is an example that should work for existing applications:

rhc env set NPM_CONFIG_PRODUCTION="true"

Or, you can set this variable as a part of your initial app-create step:

rhc app create myapplication nodejs-0.10 NPM_CONFIG_PRODUCTION="true"
like image 176
ʀɣαɳĵ Avatar answered Oct 14 '22 10:10

ʀɣαɳĵ


Found a way to specify it in source instead of during app creation. The benefit (for me) over an env var is that it applies to all ways to launch the app, including a "Launch on OpenShift" button.

Create an .openshift/action_hooks/pre_build file:

#!/bin/bash
# This makes npm not install devDependencies.
echo 'Enabling npm production'
echo 'production = true' >> $OPENSHIFT_REPO_DIR/.npmrc

That's it! I've tested and it does affect npm for this build, and the .npmrc disappears if you remove this hook in the future.

(Obviously I could also achieve this by simply adding an .npmrc to my repo, but do not want to affect people checking out the source and running npm install, only how it works on OpenShift.)

like image 38
Beni Cherniavsky-Paskin Avatar answered Oct 14 '22 08:10

Beni Cherniavsky-Paskin