2022年1月13日木曜日

Flutter web をドキュメントルート以外に設置する

 Flutter web をドキュメントルート以外に設置する方法は、Flutterのドキュメント(Configuring the URL strategy on the web)のHosting a Flutter app at a non-root locationに以下のように書かれている。

Update the <base href="/"> tag in web/index.html to the path where your app is hosted. For example, to host your Flutter app at myapp.dev/flutter_app, change this tag to <base href="/flutter_app/">.

これを受けて、私もbuild/web/index.htmlを直接書き換えていたが、忘れてそのまま設置してしまう可能性もあり、何とかならないのかと思って、build下ではなくプロジェクト直下のweb/index.htmlをみると、以下のように変数指定されている。

<base href="$FLUTTER_BASE_HREF">

これは、どこかで設定しておけるはずだと思い、いろいろ探してみたがそれらしい場所がない。

ターミナルでhelpすると、

> flutter help build web

Usage: flutter build web [arguments]

--base-href                        Overrides the href attribute of the <base> tag in web/index.html. No change is done to web/index.html file

なるほど、上記のドキュメント例なら、以下のようにbuildすればいいということか。

> flutter build web --base-href "/flutter_app/"

ドキュメントに一言、書いておいてください。

0 件のコメント:

コメントを投稿