【问题标题】:How to stop flutter web from overwriting my index.html every build?如何阻止flutter web在每次构建时覆盖我的index.html?
【发布时间】:2020-07-17 06:21:28
【问题描述】:

所以我正在使用flutter web + cloud firestore

要让 Cloud Firestore 正常工作,我必须修改我的 index.html。问题是每次我运行时

flutter build web

它覆盖了我的 index.html,我必须手动重新添加所有必要的代码 sn-ps 才能让它再次工作。

我可以在不覆盖 index.html 的情况下运行 flutter build web 吗?

另一个相关问题是,当我将站点部署到 firebase 时,它​​工作正常,但是当我在本地运行此站点以进行测试时

flutter run -d chrome

当它在 chrome 上运行时,该站点再次使用全新的 index.html 没有必要的代码,因此它不起作用。我没有机会编辑 index.html 以应用必要的代码,因为它会立即构建和运行。

有解决办法吗?

【问题讨论】:

    标签: flutter dart flutter-web


    【解决方案1】:

    您应该修改<project>/web 文件夹中的index.html 文件,而不是<project>/build/web 文件夹中的文件。该文件将在构建过程中复制到<project>/build/web 文件夹。

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <title>Flutter web</title>
      <link href="https://fonts.googleapis.com/css?family=Raleway&display=swap" rel="stylesheet">
      <script defer src="main.dart.js" type="application/javascript"></script>
      <script src="https://www.gstatic.com/firebasejs/6.6.0/firebase-app.js"></script>
      <script src="https://www.gstatic.com/firebasejs/6.6.0/firebase-auth.js"></script>
    </head>
    
    <body>
      <h1>This text will be copied to the target HTML, but covered by flutter web app</h1>
    </body>
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 2020-04-07
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      相关资源
      最近更新 更多