How to deploy node that uses Gulp to heroku

I was able to get this to work by adding this into my "package.json" file:

"scripts": {
  "start": "node app",
  "postinstall": "gulp default"
}

The postinstall script is run after the build pack. Check this for more information. The only annoying thing is that all of your dependencies have to live under "dependencies" instead of having separate "devDependencies"

I didn't need to do anything else with buildpacks or configuration. This seems like the simplest way to do it.

I wrote about the process I used here


You can do it!

There were a few key measures that helped me along the way:

  1. heroku config:set NODE_ENV=production - to set your environment to 'production'
  2. heroku config:set BUILDPACK_URL=https://github.com/krry/heroku-buildpack-nodejs-gulp-bower - to enable a customised Heroku buildpack. I incorporated elements of a few to make one that worked for me.
  3. A gulp task entitled heroku:production that performs the build tasks that need to happen on the heroku server when NODE_ENV===production. Here's mine:

    var gulp = require('gulp')
    var runSeq = require('run-sequence')
    
    gulp.task('heroku:production', function(){
      runSeq('clean', 'build', 'minify')
    })
    

    clean, build, and minify are, of course separate gulp tasks that do the magic gulpage

  4. If your application lives in /app.js, either:

    (A) make a Procfile in the project root that contains only: web: node app.js, or

    (B) add a start script to your package.json:

    "name": "gulp-node-app-name",
    "version": "10.0.4",
    "scripts": {
      "start": "node app.js"
    },
    
  5. And like @Zero21xxx says, put your gulp modules in your normal dependencies list in package.json, not in the devDependencies, which get overlooked by the buildpack, which runs npm install --production

The easiest way I found was:

  1. Setup gulp on package.json scripts area:

    "scripts": {
      "build": "gulp",
      "start": "node app.js"
    }
    

    Heroku will run build before starting the app.

  2. Include gulp on dependencies instead of devDevependencies, otherwise Heroku won't be able to find it.

There is more relevant info about it on Heroku Dev Center: Best Practices for Node.js Development