我想开发 angular 6 应用程序,但在部署 firebase 后只显示欢迎页面。
这是我部署的步骤。
ng build --prod
dist
目录中的子文件夹中,因此我将包含 index.html 的子目录中的所有内容复制到 dist/
.但在完成所有这些之后,我仍然在链接中看到欢迎页面。
我做错了什么!?
尝试: 8. 文件 dist/index.html 已经存在。覆盖? (是/否)否 并以隐身模式打开指向您的应用程序的链接。说真的,我坚持了几个小时,因为这个 firebase 索引在我的案例中被缓存了,所以这就是为什么我在部署后看不到我的应用程序的原因。
问题是: firebase 正在寻找
index.html
文件,有时它不直接存在于 dist
目录中
解决方案: 将
public
中的firebase.json
路径更新为"public":"dist/ProjectName"
或index.html
文件夹中的dist
文件路径
例子
{
"hosting": {
"public": "dist/<YourProjectName>",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/dist/index.html"
}
]
}
}
浏览器缓存也是我的问题。如上所述,尝试隐身或使用 proxysite.com(非常有用的网站)以避免浏览器缓存
就我而言,我在项目目录中初始化 firebase (
src
)。只需检查您所在的目录。它应该在顶层。
构建并尝试部署后,由于网页已缓存,因此它将相同。所以要确保在
incognito
.中使用
检查终端上的路径。如果问题仍然存在,则删除 firebase 自动创建的文件夹并部署项目
配置为单页应用(将所有url重写为/index.html)?不 ?使用 GitHub 设置自动构建和部署?否
此错误是由您网站文件夹的公用文件夹中的 index.html 生成的。
在我的例子中,我必须在 firebase.json 中将
public
更改为 dist
,以便在我将 Firebase 函数添加到我的项目后它指向我的 dist 文件夹(而不是包含持有页面的公用文件夹):
"hosting": {
"public": "dist",
...
}
欢迎页面是在 public 文件夹中自动生成的 index.html 文件。我用我自己的 index.html 文件替换了那个文件,然后使用
firebase deploy --only hosting
命令来更新更改。
首先你应该登录 firebase 登录 在那之后写命令 firesbe init
第一步 1)你想用什么作为你的公共目录? (公共)dist/projectname 2)文件dist/index.html已经存在。覆盖? (是/否)N
完成流程后 你应该运行(npm run build)命令并生成构建文件 之后你应该得到 firebase.json 并将构建文件夹放在公共目录中 { “托管”:{ “公共”:“构建”, “忽略”: [ “firebase.json”, "/.*", “/node_modules/” ], “重写”:[ { “来源”:“”, “目的地”:“/dist/index.html” } ] } }
最后一个并非最不重要的 firebase 部署。工作完美
这对我有用:
现在运行如下:
$ firebase init hosting
? File build/web/index.html already exists. Overwrite? No
$ firebase deploy --only hosting
firebase 初始化托管 ?文件 build/index.html 已经存在。覆盖?不 npm 运行构建 firebase 部署——仅托管