如何在本地浏览器中打开已编译的 Flutter web index.html?

How to open compiled Flutter web index.html in browser locally?

运行 flutter build web/build/web/ 中创建 index.html 文件以及

assets                    icons                     manifest.json
favicon.png               index.html                version.json
flutter_service_worker.js main.dart.js

当前的 flutter 频道是测试版。

$ flutter channel

Flutter channels:  
  master  
  dev  
* beta  
  stable

flutter --version

Flutter 1.25.0-8.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 8f89f6505b (2 weeks ago) • 2020-12-15 15:07:52 -0800
Engine • revision 92ae191c17
Tools • Dart 2.12.0 (build 2.12.0-133.2.beta)

当我尝试在 Chrome 浏览器中打开 /build/web/index.html 时,它显示空白。是正常的还是我需要安装任何节点包才能使它 运行?

注意:我遵循了这个文档 https://flutter.dev/docs/get-started/web

是否与index.html中的这段代码有任何关系,似乎没有包含在较早的flutter版本中?

  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    Fore more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

您需要从 npm 安装 node.js 服务器到 运行 上的网站。

npm install -g http-server

将目录更改为 /build/web 和 运行 本地主机上的服务器:

npx http-server

添加到主题中,您还可以使用python来提供它:Set up a local testing server

\[flutter_project]\build\web> python -m http.server

\[flutter_project]\build\web> python -m SimpleHTTPServer

然后前往localhost:8000