Install devDependencies on Heroku

放肆的年华 提交于 2020-11-25 06:08:42

问题


I would like to have Heroku build my app after I push it so that I don't have to push the build folder up every time I make a change. However heroku only installs the dependencies from the package.json and grunt (my build tool) and all of its components are in devDependencies. I would like to keep them there where they belong. What's the workaround here?


回答1:


Heroku by default installs only the production dependencies, ignoring the development dependencies under devDependencies.

Setting the npm production variable to false do the trick:

heroku config:set NPM_CONFIG_PRODUCTION=false

More info are available at the Heroku Node.js Support page.




回答2:


Keeping NPM_CONFIG_PRODUCTION true, I used Heroku's script hooks:

"scripts": {
  ...
  "heroku-prebuild": "export NPM_CONFIG_PRODUCTION=false; export NODE_ENV=; NPM_CONFIG_PRODUCTION=false NODE_ENV=development npm install --only=dev --dev",
  "heroku-postbuild": "export NPM_CONFIG_PRODUCTION=true; export NODE_ENV=production;",
   ...
},

(Finally) worked for me.




回答3:


scripts": {
  ...
  "heroku-prebuild": "npm install --only=dev"
}

This was enough for me. Thanks to PixnBits for the hint about heroku-prebuild. Also - my problem was with babel. I ended up moving babel-preset-es2015 and other presets into dependencies otherwise babel complained about presets.

Update: 8/11/2017 I've been having trouble with this. It seems like things have changed (and npm is on 5.3 now). But what I see is that the heroku-prebuild script is getting run, and then the post-install script is getting run (but I was only trying to install -dev).

So what I have been doing that works is to just run:

heroku config:set NPM_CONFIG_PRODUCTION=false

And just leave it set that way. I'd love a better solution.




回答4:


To unintall dependencies you need to do these

  1. Update NPM_CONFIG_PRODUCTION

    heroku config variable set

    NPM_CONFIG_PRODUCTION=false

  2. Add heroku-prebuild:

    scripts": {
      ...
      "heroku-prebuild": "npm install"
    }
or

    scripts": {
      ...
      "heroku-prebuild": "npm install --only=dev"
    }



回答5:


you can use this in your build script "build": "npm install --only=dev" should in case you still want to perform more operations e.g transpiling your code with babel you can do something like this "build": "npm install --only=dev && babel src --out-dir dist --copy-files"



来源:https://stackoverflow.com/questions/22954782/install-devdependencies-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!