LoginSignup
4
4

More than 5 years have passed since last update.

Heroku上でもgulp-webserverを使う

Last updated at Posted at 2015-06-05

Heroku で Node.js を動かすときのポイントはこちら。

  • Procfile か npm start でアプリが起動するように
  • 0.0.0.0:$PORT ないし hogehoge.heroku.com:$PORT を listen する

gulp-webserver の場合、デフォルトが localhost:8000 なので変更が必要です。

gulp.task('serve', function() {
    gulp.src('public')
        .pipe(webserver({
            host: process.env.HOST || 'localhost', // $HOST は独自定義
            port: process.env.PORT || 8000
        }));
});

ホスト名は環境変数で取得できないようなので、手動で heroku config:set HOST=0.0.0.0 とかしてください。ローカルで実行する際も同じでよければ、env使わずに埋め込んでもいいと思いますが。

で、 package.json の scripts.startgulp serve とか書いておけば、 Heroku で動きます。

ローカルで使っているビルド・実行プロセスがそのまま使えるのはとても便利ですね。

参考

4
4
0

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
4
4