LoginSignup
13
16

More than 5 years have passed since last update.

gulpやgruntでbuildしたファイルをHerokuにどうdeployするか

Last updated at Posted at 2015-05-24

gulpやgruntでbuildされたファイルは通常gitignoreしてあるので困った

3通り方法見つけました。
自分は一番目の方法でしばらくやってみることにしました。

deploy用の一時branchを作る

#!/bin/bash
set -e

# Create new deploy branch based on master
git checkout -b deploy
# gulp comands to build our site
gulp build
# the dist/ directory is in my .gitignore, so forcibly add it
git add -f build/
git commit -m "Deploying to Heroku"
# Push it up to heroku, the -f ensures that heroku won't complain
git push heroku -f deploy:master
# Return to the last branch
git checkout -
# Delete current deploy branch
git branch -D deploy

一時的にdeployブランチを作成し、そこでbuild後にgitignoreしてあるファイルをforce addしています。
pushし終えたら元のブランチに戻って一時ブランチを削除しています。

この方法でいいなと思ったのは、少しの変更をいちいちcommitしないでもherokuにpush出来てしまうという点です。
開発初期段階ではいちいちcommit&pushするのが嫌だったので。。

参考: http://stackoverflow.com/questions/13784600/how-to-deploy-node-app-that-uses-grunt-to-heroku

heroku上でbuildを実行(postinstallにgulpコマンドを記述)

  "scripts": {
    "postinstall": "gulp build",
    "start": "node build/server.js",
  }

heroku上でpakageのinstallが完了したあとにpostinstallが実行されます。
なのでpostinstallにgulpコマンドを書くという方法もありです。
ただ、コマンド実行に必要なpackageを"devDependencies"ではなくて"Dependencies"に記述しないとダメなようです。

参考: https://medium.com/@adambretz/heroku-gulp-c96dc3a8044d

ローカルでBuildしたファイルをそのままpushする

ローカルでbuildを実行し、buildされたファイルをgitignoreせずにpushするという方法でもいけると思います。

13
16
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
16