Firebase:将相同的应用程序部署到多个 Firebase 项目
Firebase: deploy same app to multiple Firebase-projects
我正在尝试将我的代码部署到两个不同的 Firebase 项目,一个用于开发,一个用于生产。
my-app-dev
项目已经包含并且可以运行,所以我添加了 my-app
(用于生产)和 firebase use --add
,并选择了 my-app
。
这是我的 Firebase 配置现在的样子:
.firebaserc
{
"targets": {
"my-app-dev": {
"hosting": {
"app": [
"my-app-dev"
]
}
}
},
"projects": {
"default": "my-app-dev",
"prod": "my-app"
}
}
firebase.json
{
"hosting": [
{
"target": "app",
"public": "dist/app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
只要我部署到我的默认项目,一切正常,但是当我尝试 firebase deploy -P prod
它显示以下错误:
Deploy target app not configured for project my-app. Configure with:
firebase target:apply hosting app <resources...>
我试图找到有关此命令的更多信息,但仍然不知道要放置什么资源。总的来说,我觉得 .firebaserc
的结构非常混乱。
根据 GitHub 中的这个 comment,如果没有 "hacky" 方法就无法完成,例如在部署期间以编程方式交换 firebase.json。
Right now the Firebase CLI is built to treat projects as anonymous
environments that are functionally identical. This is important to be
able to deploy the same assets to multiple projects without having to
alter the code (including in firebase.json).
To achieve what you want, you'll need to set up a dev and prod folder,
each with their own firebase.json and each with a target only for that
specific project. Deploying different assets to different projects is
not supported now and is unlikely to be supported in the future
(however, we may allow configuring the location of firebase.json via a
flag at some point).
我遇到了同样的问题,但方式不同。
我的项目是一个 Angular 11 项目,它有 4 个不同的环境 - 部署到默认项目 (env) 的相同行为很好,但一旦我尝试部署到不同的环境环境(firebase 项目),它失败并出现相同的错误:
Deploy target ___ not configured for project ___. Configure with:
我通过添加到 .firebasesrc > targets
:
解决了这个问题
{
"projects": {
"default": "default-project"
},
"targets": {
"default-project": {
"hosting": {
"frontend": [
"default-project"
]
}
},
"staging-project": { // Added this entry.
"hosting": {
"frontend": [
"staging-project"
]
}
}
}
}
我正在尝试将我的代码部署到两个不同的 Firebase 项目,一个用于开发,一个用于生产。
my-app-dev
项目已经包含并且可以运行,所以我添加了 my-app
(用于生产)和 firebase use --add
,并选择了 my-app
。
这是我的 Firebase 配置现在的样子:
.firebaserc
{
"targets": {
"my-app-dev": {
"hosting": {
"app": [
"my-app-dev"
]
}
}
},
"projects": {
"default": "my-app-dev",
"prod": "my-app"
}
}
firebase.json
{
"hosting": [
{
"target": "app",
"public": "dist/app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
只要我部署到我的默认项目,一切正常,但是当我尝试 firebase deploy -P prod
它显示以下错误:
Deploy target app not configured for project my-app. Configure with:
firebase target:apply hosting app <resources...>
我试图找到有关此命令的更多信息,但仍然不知道要放置什么资源。总的来说,我觉得 .firebaserc
的结构非常混乱。
根据 GitHub 中的这个 comment,如果没有 "hacky" 方法就无法完成,例如在部署期间以编程方式交换 firebase.json。
Right now the Firebase CLI is built to treat projects as anonymous environments that are functionally identical. This is important to be able to deploy the same assets to multiple projects without having to alter the code (including in firebase.json).
To achieve what you want, you'll need to set up a dev and prod folder, each with their own firebase.json and each with a target only for that specific project. Deploying different assets to different projects is not supported now and is unlikely to be supported in the future (however, we may allow configuring the location of firebase.json via a flag at some point).
我遇到了同样的问题,但方式不同。
我的项目是一个 Angular 11 项目,它有 4 个不同的环境 - 部署到默认项目 (env) 的相同行为很好,但一旦我尝试部署到不同的环境环境(firebase 项目),它失败并出现相同的错误:
Deploy target ___ not configured for project ___. Configure with:
我通过添加到 .firebasesrc > targets
:
{
"projects": {
"default": "default-project"
},
"targets": {
"default-project": {
"hosting": {
"frontend": [
"default-project"
]
}
},
"staging-project": { // Added this entry.
"hosting": {
"frontend": [
"staging-project"
]
}
}
}
}