Bower install and run grunt tasks on Heroku with the default node buildpack

Edit: Looks like you don't have to include ./node_modules/.bin anymore in the postinstall. Thanks @jbuckca!

Deploying node apps to Heroku has gotten waaay more awesome (i.e. faster) in the last couple of months, first with a significant update to the default node buildpack that supports a build cache for node_modules, and other recent improvements to the build infrastructure.

If you're using a custom buildpack for your grunt build tasks, you might have missed out on some of these improvements. Luckily there is a pretty easy way to use the default buildpack instead, as long as you're OK with modifying your package.json:

package.json

{
  "scripts": {
    "postinstall": "bower install; grunt build"
  },
  "dependencies": {
    "bower": "1.2.8",
    "grunt": "0.4.2",
    "grunt-cli": "0.1.13"
  }
}

The important things to remember are:

  1. Include bower for bower, grunt and grunt-cli for grunt in your dependencies (not dev-dependencies, that won't work with the default build pack)
  2. Add a postinstall script to scripts that calls bower install; grunt {your task name}.

  3. Profit!

This won't be compatible some production build scripts, but it's frikin awesome for deploying test branches and prototypes quickly.