LoginSignup
9
8

More than 5 years have passed since last update.

Herokuでdeploy後にnode.jsでbuild処理を実行する

Posted at

Herokuでdeploy時にbuildする環境を構築してみたのでそのメモ。

ターミナルからherokuコマンドからインストール

buildpacks:heroku/nodejsをインストールすることでdeploy時にnpm installが実行されるようになる。

heroku login
heroku buildpacks:clear --app APPNANE
heroku buildpacks:heroku/nodejs

※コマンドからではなくdashboardのアプリのsetting内にあるBuildpacksからbuildpackを追加するのも可能。
https://dashboard.heroku.com/apps/APPNAME/settings

デフォルトの設定だとnpm install実行時はdependenciesのmoduleしかインストールされないがdevDependenciesのmoduleもインストールしたい場合は

heroku config:set NPM_CONFIG_PRODUCTION=false --app

を実行して設定を変更しておく

package.jsonのscript記述

npm install後の処理(主にbuild系の処理になるかと思います)をpackage.jsonに書く。

heroku-prebuildnpm install後に実行されるコマンドを指定する。
heroku-postbuildheroku-prebuild後に実行されるコマンドを指定する。

}
"scripts": {
  "heroku-prebuild": "echo This runs before Heroku installs your dependencies.",
  "heroku-postbuild": "echo This runs afterwards."
}

ref. https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process

9
8
1

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
9
8