0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

vueプロジェクトをherokuへデプロイする

0
Posted at

はじめに

vueプロジェクトをherokuへデプロイする手順を備忘録として残します。

手順

  1. vueプロジェクト作成
  2. herokuプロジェクト作成
  3. express追加
  4. server.js追加
  5. git push heroku main

プロジェクト作成

vueプロジェクトはvue-cliを使って作成しました。

vue create xxx

herokuのプロジェクトも作成します。
https://dashboard.heroku.com/new-app

express追加

vueプロジェクトをサーブするためにexpressをプロジェクトに追加します。

npm install express

server.js

expressをインストールしたらvueプロジェクトをサーブするためのjsを記述します。

server.js
const express = require('express');
const serveStatic = require('serve-static');

const app = express();
app.use(serveStatic(__dirname + "/dist"));
app.get(/.*/, (_, res) => {
  res.sendFile(__dirname + "/dist/index.html")
})

const port = process.env.PORT || 5001;
app.listen(port);
console.log('server started '+ port);

最後は下記コマンドを実行することでherokuへのデプロイが完了します。

git push heroku main

参考記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?