Run npm install --production on OpenShift

后端 未结 4 1495
一整个雨季
一整个雨季 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:19
    1. Create a .npmrc file where the node_modules folder is located.

    2. Open it with your text-editor and add this to it:

      production = true

    P.S. no semicolons or any other characters

    This will ensure that devDependencies are not installed on the OPENSHIFT server

    0 讨论(0)
  • 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.)

    0 讨论(0)
  • 2021-02-06 02:30

    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"
    
    0 讨论(0)
  • 2021-02-06 02:30

    It looks like the only solution is to update the cartridge itself. The npm install command is located in the cartridge's bin/control folder. Meanwhile, it's been fixed in the originating github repo at wshearn/openshift-origin-cartridge-nodejs so you can just install from github rather than using the Quickstart.

    0 讨论(0)
提交回复
热议问题