我有 2 个 Firebase 项目(生产和测试),并且我已在 Firebase CLI 中登录到它们。我通过调用
firebase use testing
等在它们之间切换。
我在
hosting
目录中还有一个简单的托管项目。
我创建了 2 个网站:
join
在 production
join-tst
在 testing
如何设置我的项目以便可以将相同的托管部署到两个站点?我现在的
firebase.json
现在如下。
{
"hosting": [
{
"site": "join-tst",
"public": "hosting",
"cleanUrls": true,
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source": "/",
"destination": "https://mywebsite.com/",
"type": 301
}
],
"headers": [
{
"source": "/.well-known/*",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
]
}
]
}
]
}
但是,我无法复制与云功能相同的托管体验。对于云功能我只需要切换环境然后调用
firebase use testing
firebase deploy --only functions
我可以实现这样的目标而不用担心网站名称吗:
firebase use testing
firebase deploy --only hosting
是的,您可以通过为两个项目中的两个站点分配相同的目标名称来实现这一点:
firebase use testing
firebase target:apply hosting your-target-name join-tst
firebase use production
firebase target:apply hosting your-target-name join
那么
firebase.json
需要是:
"hosting": [
{
"target": "your-target-name",
"public": "hosting"
...
}
]