我有两个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
,因为我希望将dev项目设置为默认项目...
所以我的.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"
]
}
}
现在,当我运行这些行时,Web应用程序已部署到产品环境,functions
已部署到开发环境...
firebase use myapp-dev
firebase deploy
运行firebase target:apply hosting myapp myapp-dev
帮助了!
答案 0 :(得分:0)
我认为您的配置应该是这样的。
文件.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
答案 1 :(得分:0)
就我而言,我有同一个应用程序部署到两个不同的环境(开发和生产)。在这种情况下,文档不是很清楚,需要花一些时间才能获得正确的配置。
.firebaserc
{
"projects": {
"production": "myapp-prod",
"development": "myapp-dev"
},
"targets": {
"myapp-prod": {
"hosting": {
"myapp": [
"site-name-prod"
]
}
},
"myapp-dev": {
"hosting": {
"myapp": [
"site-name-dev"
]
}
}
}
}
firebase.json
{
"hosting": [{
"target": "myapp",
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}]
}
要部署到生产运行
firebase use production
firebase deploy
部署到开发中
firebase use development
firebase deploy
在项目中运行firebase deploy时,它将使用firebase.json的托管部分中指定的目标部署到.firebaserc中目标的托管部分中指定的站点名称