ngrokで、デプロイできたが、firebaseを使ってデプロイする方法があるらしいのでしらべることにした。
https://firebase.google.com/docs/hosting?hl=ja
firebase init hosting
publicディレクトリができる。ダミーのindex.htmlができる
flutter build web
cd public firebase deploy --only hosting
デフォルトだと、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
https://www.flutter-study.dev/host-web-app/hosting
https://qiita.com/my_programming/items/5950b7e27161dc9ec838
https://dev.classmethod.jp/articles/firebase-hosting-deploy/