angular - 如何将我的 Angular 应用程序部署到不同的 firebase 环境?
问题描述
我想让我的 Angular 应用程序在两个不同的网站上运行,一个用于开发/展示目的,一个用于生产。
为此,我创建了两个 firebase 项目(app 和 appDev),每个项目都有自己的实时数据库。
如何正确地将我的应用程序部署到这些环境?我需要使用 firebase CLI 还是 angular CLI?
我发现了 angular src/environments 文件夹,其中包含我的 environment.ts 和 environment.prod.ts - 但实际上它似乎没有改变任何东西,我可以将错误数据放入该文件,它仍会正确部署到我的开发环境(我最初配置 ng add @angular/fire)并使用开发数据库运行。
我还发现了关于 firebase 目标的信息,但是对于我想要实现的目标,它们似乎非常强大(具有不同的资源类型和东西),那时我可能无法使用 ng deploy,所以我不确定这是否是正确的方向。
第三种方法似乎是“firebase 使用 --add”并添加多个项目。
现在我可以在任何我想切换的时候重新初始化firebase,这可行,但不能这样想。任何指针?环境、目标和项目之间的假定区别是什么?
解决方案
在文件 angular.json 例如:“配置”:
{ "staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"demo": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.demo.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
src/environments/environment.staging.ts
export const environment = {
production: true,
apiUrl: 'https://firebase/api'
};
模型:
import {environment} from './environments/environment';
this.http.get(`${environment.apiUrl}/some/select_options`, { params })
.pipe();
并构建或运行:
ng build --configuration=staging
推荐阅读
- asp.net-mvc - Umbraco 8,无法授权升级
- sql - 具有聚合条件的字段值计数
- r - 为什么我的动画 ggplot 图超出了相应的 x 限制?
- amazon-web-services - 如何防止长寿命的 Selenium 进程生成 OOM 错误?
- c++ - 使用 OpenGLES2 在 3D 场景上绘制 2D 文本?
- javascript - Youtube API 的规范最近有变化吗?
- php - 为什么当用户新注册和已经登录时,注销(护照)的行为会有所不同?
- chainlink - Chainlink VRF - 如何检查 fullfillRandomness 结果是否有效
- python - 如何改进处理多个请求的烧瓶应用程序?
- python - 如何在 PyCharm 中禁用这个示例程序?