I’m using grunt and also grunt plugins like grunt-contrib-copy, grunt-contrib-mincss (that listed as npm dependencies for my application).
Also I don’t commit npm_modules folder and public folder, where all generated files are. And I can’t figure out how to build my app (I have grunt build command) after deploy and setup my server (it’s already looking for public folder).
I saw some stuff like grunt-heroku-deploy, but it seems me a bad idea to commit before upload. Maybe there are some gentle decisions… Any thoughts?
npm has a support for a
postinstallstep (among many others) that might be just what you’re looking for.The node.js heroku buildpack runs this command when you push to heroku to resolve build dependencies:
https://devcenter.heroku.com/articles/nodejs-support#build-behavior
If you take a look at the npm documentation, you can setup a series of scripts to run either before or after anyone runs
npm installfor your package. It’s configured in thescriptsproperty ofpackage.json. Thescriptsproperty allows to run custom scripts (includinggrunt) when certain things happen in a package’s lifecycle.For example, to echo some text and run the
gruntcommand whenever anyone (including Heroku) runsnpm install, add this to yourpackage.json:https://npmjs.org/doc/scripts.html
Important caveats:
postinstallscript, check the error output if thegruntcommand doesn’t execute.gruntandgrunt-climust be listed as adependencyin yourpackage.jsonso it gets installed by Heroku. Listing them underdevDependenciesis not sufficient since Heroku won’t install those. Also, note that Heroku won’t install it as a global package so to execute it on Heroku you’re going to have to use a relative path (as it is configured above).If this doesn’t work (you’ll probably need to fiddle with the relative paths a bit), then you might want to consider writing your own custom buildpack for Heroku.
Update
As of 0.4, the
gruntpackage no longer contains thegruntbinary, which is now part of thegrunt-clipackage. The answer has been updated to reflect this.