How to deploy node that uses Gulp to heroku

后端 未结 8 1295
遥遥无期
遥遥无期 2020-12-07 16:21

I\'m using gulp and also gulp plugins like gulp-minify-css, gulp-uglify etc (that listed as npm dependencies for my application).

Also I don\'t commit npm_modules fo

8条回答
  •  生来不讨喜
    2020-12-07 17:18

    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

提交回复
热议问题