Firebase未运行index.html文件

use*_*210 23 html firebase firebase-hosting firebase-tools

我是一个非常新的程序员,通过Firebase教程.我已经完成了本教程的步骤1-5(https://codelabs.developers.google.com/codelabs/firebase-web/#5).我已将"将Firebase添加到您的网络应用程序"js代码添加到html文件,并设置了Firebase CLI.但是,当我运行firebase服务器时,除了没有显示index.html文件中的代码之外,一切似乎都有效.

我在正确的目录中,我的控制台说"服务器监听:http:// localhost:5000".但是,在localhost 5000上,它显示了一个通用的"欢迎使用Firebase托管:您已经看到了这一点,因为您已经成功设置了Firebase托管.现在是时候构建非凡的东西!" 框而不是index.html文件中的应用程序界面代码.它是我目录中唯一的html文件.好像我错过了很简单的东西.谢谢您的帮助.

use*_*210 22

我想出了我的答案.发布的index.html文件位于"公共"文件中,该文件是在"firebase init"阶段创建的.我用我的应用程序替换了占位符html文件.

  • 如何替换这个公共index.html文件? (7认同)

Dom*_*omi 15

问题是firebase init令人难以置信的粗暴.它只是覆盖index.htmlpublic文件夹中的文件......没有确认,没有安全网,没有任何东西.

解决此问题的唯一方法是重新生成您自己的index.html文件.如果你没有备份或其他方法重新生成你的index.html文件......那么......太糟糕了!

通常,firebase使用webpack(或其他构建工具)进行设置的步骤有点像这样:

  1. firebase login
  2. firebase init
  3. your-build-command-here
  4. firebase deploy

请注意,您只需要在该计算机上设置构建时(或者在发布新的firebase修订版时)第一次执行前两个步骤.要重新部署,它只是:

  1. your-build-command-here
  2. firebase deploy

UPDATE

在最新版本中它至少会询问你是否应该覆盖:)

  • “简直令人难以置信” (2认同)

小智 10

Firebase托管未显示应用程序?

此问题可能有两个原因

第一步:

确保包含index.html的公用文件夹(在firebase.json中定义)“ dist”未被firebase init命令修改,如果是,则将其替换为原始项目index.html

供参考(dist为标准,但您可能有所不同)

{ "hosting": { "public": "dist"} }
Run Code Online (Sandbox Code Playgroud)

第二步:

确保在项目的index.html中配置基本href

<base href="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/">
Run Code Online (Sandbox Code Playgroud)

和其他捆绑文件为

<script type="text/javascript" src="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/runtime.a66f828dca56eeb90e02.js">
Run Code Online (Sandbox Code Playgroud)

<script type="text/javascript" src="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/main.2eb2046276073df361f7.js">
Run Code Online (Sandbox Code Playgroud)

第三步运行命令-Firebase部署

请享用 !;)


小智 7

对于遇到此问题的任何其他人。尝试以隐身模式启动 - 浏览器已为我缓存。

/sf/answers/3952772421/


Mon*_*lla 6

首先,您需要检查index.html项目部署后的情况。在这些命令步骤之后:

firebase login

firebase init

firebase deploy
Run Code Online (Sandbox Code Playgroud)

您的真实index.html文件可能会被 firebase 覆盖,generic file这就是出现问题的原因。index.html因此,在项目部署后更改代码。如果您在网页上看到此框

在此输入图像描述

提示:在部署之前将完整的项目复制到 PC 中的任何位置。

否则检查目录中的文件路径,index.html 的路径必须正确。


All*_*ітy 5

对于带有cli的角度2或6,将.(dist)用作公共目录,

$ ng build --prod
$ cd dist/
$ firebase init
 ? What do you want to use as your public directory? .
 ? Configure as a single-page app (rewrite all urls to /index.html)? Yes
 ? File ./index.html already exists. Overwrite? No
$ firebase deploy
Run Code Online (Sandbox Code Playgroud)

  • 我正在使用 Angular,我必须为公共目录指定 dist/my-app-name,因为这是运行 ng build --prod 后 angular 放置我的 index.html 文件的地方。如果您指定 dist,您不想通过 cd 进入 dist 文件来运行 firebase init,只需从您的主项目文件夹中运行它即可。 (2认同)