サイトをデプロイする

ここまでで作成したサイトをFirebaseにデプロイしWeb公開します。

デプロイするデータをビルドする

デプロイ用にサイトを実ファイルにビルドします。

  1. コマンドラインツール(Windowsであればコマンドプロンプト、Macであればターミナル)を開く。
  2. 本プロジェクトのルートフォルダに移動する。
  3. yarn buildを実行し、プロジェクトファイルをビルドします。
$ yarn build

yarn run v1.15.2
$ vuepress build

 WAIT  Extracting site metadata...
[4:42:27 PM] Compiling Client
[4:42:27 PM] Compiling Server
[4:42:34 PM] Compiled Server in 6s
[4:42:40 PM] Compiled Client in 13s
 WAIT  Rendering static HTML...

 DONE  Success! Generated static files in .vuepress/dist.

✨  Done in 16.10s.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

.vupress/distフォルダが作成され、ビルド済みのデータが格納されます。

Firebaseへログインする

デプロイ先のFirebaseにログインします。

  1. コマンドラインツール(Windowsであればコマンドプロンプト、Macであればターミナル)を開く。
  2. firebase login を実行して、firebaseにログインする。
$ firebase login
1
  1. Firebaseから情報収拾の可否を聞かれたらYnを入力する。
? Allow Firebase to collect anonymous CLI usage and error reporting information? Yes

Visit this URL on any device to log in:
1
2
3
  1. googleアカウント認証ページで任意のgooleアカウントを選択し、アクセスを許可する。

Image from Gyazo

ヒント

ログインに成功すると下記の画面が表示されます。

  • Webブラウザ:
    Image from Gyazo
  • コマンドライン:
✔  Success! Logged in as <your-email-address>
1

Firebaseプロジェクトを開始する

Firebaseのプロジェクトを開始します。

  1. コマンドラインツール(Windowsであればコマンドプロンプト、Macであればターミナル)を開く。
  2. 本プロジェクトのルートフォルダに移動する。
  3. firebaseプロジェクトを初期化する。
# firebaseプロジェクトを初期化します。
$ firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:
1
2
3
4
5
6
7
8
9
10
  1. サービスメニューからHosting を選択します。
? Which Firebase CLI features do you want to set up for this folder? Press Space to
 select features, then Enter to confirm your choices.
 ◯ Database: Deploy Firebase Realtime Database Rules
 ◯ Firestore: Deploy rules and create indexes for Firestore
 ◯ Functions: Configure and deploy Cloud Functions
❯◉ Hosting: Configure and deploy Firebase Hosting sites
 ◯ Storage: Deploy Cloud Storage security rules
1
2
3
4
5
6
7

ヒント

  • 選択は▲/▼キーでメニューを選んでからスペースキーをクリックします。
  • 決定はEnterキーをクリックします。
  • mBaaSとしてFirebaseはWebサイトのホスティング以外にも、サーバーレスと呼ばれる構成を実現する多くの機能を提供しています。本手順では最小限の利用としてHostingのみを選択しています。
  1. [create a new project]を選択する。
? Select a default Firebase project for this directory:
❯ [create a new project]
  [don't setup a default project]
1
2
3
  1. 公開用のフォルダを.vuepress/distと入力する。
? What do you want to use as your public directory? (public) .vuepress/dist
1
  1. 上書き可否を聞かれたら全てNを入力する。
? Configure as a single-page app (rewrite all urls to /index.html)? No
? File .vuepress/dist/404.html already exists. Overwrite? No
i  Skipping write of .vuepress/dist/404.html
? File .vuepress/dist/index.html already exists. Overwrite? No
i  Skipping write of .vuepress/dist/index.html

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

✔  Firebase initialization complete!

Project creation is only available from the Firebase Console
Please visit https://console.firebase.google.com to create a new project, then run firebase use --add
1
2
3
4
5
6
7
8
9
10
11
12
13
  1. Firebase console(https://console.firebase.google.com)をブラウザで表示して、Googleアカウントでログインする。

Image from Gyazo

  1. プロジェクトを追加をクリックする。

Image from Gyazo

  1. 任意のプロジェクト名を入力し、測定管理者間のデータ保護条項にチェックを入れて、プロジェクトを作成するをクリックする。

Image from Gyazo

ヒント

上記の画面で表示されるプロジェクトIDは、下記の手順で必要になります。

  1. プロジェクト準備完了の画面が表示されたら、次へをクリックします。

Image from Gyazo

Firebaseにデプロイする

ビルドしたファイルをFirebaseにデプロイします。

  1. コマンドラインツール(Windowsであればコマンドプロンプト、Macであればターミナル)を開く。
  2. firebase use --addを実行し、使用するFirebaseプロジェクトを選択する。
$ firebase use --add

? Which project do you want to add?
❯ jamstack-xxxx
1
2
3
4

ヒント

Firebaseプロジェクトを開始するの手順10のプロジェクトIDを選択してください。

  1. aliasを聞かれたら、任意のエイリアスを設定する。
? What alias do you want to use for this project? (e.g. staging) hosting

Created alias hosting for jamstack-xxxx.
Now using alias hosting (jamstack-xxxx)
1
2
3
4
  1. firebase deployを実行し、Firebaseにデータをデプロイする。
$ firebase deploy

=== Deploying to 'jamstack-xxxx'...

i  deploying hosting
i  hosting[jamstack-xxxx]: beginning deploy...
i  hosting[jamstack-xxxx]: found 2 files in .vuepress/dist
✔  hosting[jamstack-xxxx]: file upload complete
i  hosting[jamstack-xxxx]: finalizing version...
✔  hosting[jamstack-xxxx]: version finalized
i  hosting[jamstack-xxxx]: releasing new version...
✔  hosting[jamstack-xxxx]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/jamstack-xxxx/overview
Hosting URL: https://jamstack-xxxx.firebaseapp.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  1. Hosting URL: の右側に表示されたURLをブラウザで表示する。

Image from Gyazo

無事にWeb公開されたことが確認できます。

最終更新日: 2019-6-9 08:07:28