gpt4 book ai didi

使用多个项目时 Firebase 部署到错误的托管

转载 作者:行者123 更新时间:2023-12-03 20:55:30 24 4
gpt4 key购买 nike

我有两个 firebase 项目:myapp用于生产和 myapp-dev对于开发环境。
我首先使用 firebase cli 用“myapp”初始化我的项目,因此所有文件都是由此生成的,包括托管资源 myapp (所以我可以将我的应用程序部署到 myapp.web.app )。

然后我添加了第二个 firebase 项目(“myapp-dev”)。我运行那些

firebase use --add myapp-dev  # I have selected the right myapp-dev firebase project and set `dev` as short name
firebase target:apply hosting myapp-dev myapp # note here that I also use name "myapp" as resource

我已经手动更改了我的 .firebasesrc因为我希望开发项目是默认的...

所以我的 .firebasesrc看起来像这样
{
"projects": {
"default": "myapp-dev",
"prod": "myapp"
},
"targets": {
"myapp": {
"hosting": {
"myapp": [
"myapp"
]
}
},
"myapp-dev": {
"hosting": {
"myapp": [
"myapp"
]
}
}
}
}

firebase.json
{
"hosting": [
{
"target": "myapp",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}


现在,当我运行这些行时,webapp 被部署到 prod 环境中, functions到开发环境...
firebase use myapp-dev
firebase deploy

编辑

运行 firebase target:apply hosting myapp myapp-dev有帮助!

最佳答案

我认为你的配置应该是这样的。

文件 .firebasesrc

  "targets": {
"myapp-dev": {
"hosting": {
"myapp-dev": [
"myapp-dev"
],
"myapp": [
"myapp"
]
}
}
}

文件 firebase.json:
  "hosting": [
{
"target": "myapp-dev",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
{
"target": "myapp",
"public": "dist/myapp", /* folder */
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
]

然后使用 target 进行部署 documentation

关于使用多个项目时 Firebase 部署到错误的托管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61025639/

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