Flutter Web应用程序不会部署到Firebase托管

qpgpyjmq  于 2023-05-19  发布在  Flutter
关注(0)|答案(2)|浏览(135)

我的Flutter应用程序在Chrome(Web)模拟器中看起来很棒,并在本地服务器上运行。
我导航到这个目录:

Users/TDK/StudioProjects/kabbalah/build/web/

我安装了Firebase CLI工具,然后运行

firebase init hosting

我不确定这个问题:

? Configure as a single-page app (rewrite all urls to /index.html)? (y/N)

我回答y。答案是

✔  Firebase initialization complete!

然后我就跑了

firebase deploy --only hosting

答案是

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/kabbalah-numerology/overview
Hosting URL: https://kabbalah-numerology.web.app

当我转到项目控制台时,我看到

Deployed

当我转到https://kabbalah-numerology.web.app时,我得到这个屏幕:

我不应该看到我的Web应用程序吗?我是否从错误的目录部署?
我打开Safari查看Chrome是否缓存了一个旧网页,但我得到了相同的屏幕。
我把这个代码块放到index.html中。没什么区别。

<body>
<script>
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "my-super-secret-key",
  authDomain: "kabbalah-numerology.firebaseapp.com",
  projectId: "kabbalah-numerology",
  storageBucket: "kabbalah-numerology.appspot.com",
  messagingSenderId: "my-sending-id",
  appId: "my-app-id",
  measurementId: "my-measurement-id"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
</body>
fkvaft9z

fkvaft9z1#

检查firebase.json文件,它控制您的主机设置。最有可能的是,其中的public文件夹(它决定了从哪个目录提供文件)指向了错误的位置。
我通常在项目的根目录中运行firebase init,然后在firebase.json中将public指向flutter web构建的输出。

gorkyyrv

gorkyyrv2#

这对我很有效。
运行flutter cleanflutter build web --releasefirebase init后,您将到达如图所示的位置:

File build/web/index.html already exists处选择No。是否覆盖?(y/N)。这是因为Firebase用自己的代码覆盖了/index. html,生成您正在查看的屏幕。
然后,你可以运行firebase deploy
或者,如果您已经看到***firebase主机安装完成***屏幕,只需运行flutter build web --release将build/web/index.html配置到您的项目和firebase deploy

相关问题