gpt4 book ai didi

flutter - 如何在 Firebase 主机上托管 Flutter Web(蜂鸟)

转载 作者:IT王子 更新时间:2023-10-29 07:07:33 25 4
gpt4 key购买 nike

我创建了一个 flutter web 项目并在本地主机上运行良好。所以我计划在 firebase 中托管该网站。我按照它成功部署的命令进行操作,但它在控制台中仅显示黑屏并显示错误消息。

错误:

源“https://myportfolioflutterweb.firebaseapp.com/web/main.dart.js”加载失败”。SyntaxError: 预期的表达式,得到 '<'[了解更多]

我的项目结构:

enter image description here

firebase.json:

{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source": "/",
"destination": "/web/index.html",
"type": 302
}
]
}
}

命令:

enter image description here

注意:当我将公共(public)目录作为公共(public)文件夹时,它会创建 index.html。我手动删除了文件并导航到 web/index.html 路径

最佳答案

最后,我解决了这个问题。我在 firebase 托管的公共(public)文件夹中导航错误的路径。要首先部署 flutter web,我需要使用以下命令构建项目

构建

webdev build

在我构建项目之后,它会在项目中创建一个构建文件夹 enter image description here在我以 root 身份公开路径之前,但正确的路径是构建

正确路径:

 What do you want to use as your public directory? build

我在下面附上了 firebase 托管部署的完整命令,

enter image description here

关于flutter - 如何在 Firebase 主机上托管 Flutter Web(蜂鸟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56206091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com