如何在Firebase托管上托管Flutter Web(Hummingbird) [英] How to host Flutter Web (Hummingbird) on Firebase Hosting

查看:69
本文介绍了如何在Firebase托管上托管Flutter Web(Hummingbird)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Flutter Web项目,并在localhost中正常工作.因此,我计划将网站托管在firebase中.我遵循了已成功部署的命令,但在控制台中仅显示黑屏,并显示错误消息.

I created a flutter web project and work fine in localhost. So I planned to host the website in firebase. I followed the commands it deployed successfully but it shows only black screen in the console it shows error message.

错误:

的源" https://myportfolioflutterweb.firebaseapp.com/加载失败. web/main.dart.js ". SyntaxError:期望的表达式,得到了'<'[了解详情]

Loading failed for the with source "https://myportfolioflutterweb.firebaseapp.com/web/main.dart.js". SyntaxError: expected expression, got '<'[Learn More]

我的项目结构:

firebase.json:

firebase.json :

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

命令:

注意:当我将public dir作为公用文件夹时,它将创建index.html.我手动删除了文件,然后导航到路径为web/index.html

Note: When I give public dir as the public folder it creates index.html. I deleted the file manually and navigate to the path as web/index.html

推荐答案

最后,我解决了这个问题.我在Firebase托管的公用文件夹中导航错误的路径.要首先部署Flutter网站,我需要使用以下命令构建项目

Finally, I solved the issue. I navigate the wrong path in public folder on firebase hosting. To deploy flutter web first I need to build the project using below command

构建

webdev build

构建项目后,它将在项目内部创建一个构建文件夹 在我以root身份公开路径但正确的路径是build之前

After I build the project It creates a build folder inside the project Before I public path as root but the correct path is build

正确的路径:

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

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

I attached full command of firebase hosting deployment below,

这篇关于如何在Firebase托管上托管Flutter Web(Hummingbird)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆