<!-- markdown -->

# 目次
[TOC]

# はじめに
ngrokで、デプロイできたが、firebaseを使ってデプロイする方法があるらしいのでしらべることにした。

# Firebase Hosting
https://firebase.google.com/docs/hosting?hl=ja

# 初期化
    firebase init hosting

publicディレクトリができる。ダミーのindex.htmlができる

# 手順

    flutter build web

    cd public
    firebase deploy --only hosting

## firebase.jsonの修正

デフォルトだと、publicフォルダになっているので、flutterのwebビルドのデフォルトの出力先に変更する。

### 変更後のサンプル
    {
      "hosting": {
        "public": "build/web",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    }

## 環境変数を設定した状態でデプロイできるか検証

    # build_with_env.sh
    #!/bin/bash
    
    # .env ファイルから環境変数を読み込む
    export $(cat .env | xargs)
    
    # flutter build web コマンドを実行する
    flutter build web --dart-define=API_URL=$API_URL --dart-define=OTHER_VAR=$OTHER_VAR

このスクリプトを使ってビルドする場合:

スクリプトファイル(例:build_with_env.sh)を作成します。
スクリプトファイルに実行権限を与えます。

    chmod +x build_with_env.sh

スクリプトを実行してビルドします。
    ./build_with_env.sh

# 紹介記事

## Hothingの機能を有効化する

https://www.flutter-study.dev/host-web-app/hosting

## Firebase/HostingでWebアプリを外部公開しよう
    
https://qiita.com/my_programming/items/5950b7e27161dc9ec838

## Firebase HostingでWebサイトをデプロイする

https://dev.classmethod.jp/articles/firebase-hosting-deploy/

## HostingでWebアプリ公開

https://www.flutter-study.dev/host-web-app/host-web-app

# その他
## 初心者がFlutterのDocker環境を作る
https://zenn.dev/citron633/articles/6cb3f390c6c98b

## Docker上にflutter開発環境を構築する(Linux)
## https://zenn.dev/ysuito/articles/69af1203be532d

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   最終更新のRSS