Run npm install --production on OpenShift

后端 未结 4 1492
一整个雨季
一整个雨季 2021-02-06 01:53

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 wil

4条回答
  •  鱼传尺愫
    2021-02-06 02:28

    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.)

提交回复
热议问题