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?
By default, Heroku will install all dependencies listed in package. json under dependencies and devDependencies . After running the installation and build steps Heroku will strip out the packages declared under devDependencies before deploying the application.
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
The package is automatically listed in the package. json file, under the dependencies list (as of npm 5. previously, you had to manually specify --save ). When you add the -D flag, or --save-dev , you are installing it as a development dependency, which adds it to the devDependencies list.
UPDATE: as pointed out in the comments this is no more needed because since 2018 heroku changed its default behaviour and dev dependencies are automatically installed
ORIGINAL ANSWER
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With