简体   繁体   English

Firebase用于测试和生产的独立firebase.json文件-使用Angular环境文件变量吗?

[英]Firebase separate firebase.json file for test and production - use Angular environments file variables?

The settings for Firebase deployment - Firestore, Hosting, and Cloud Functions - are in the firebase.json file. Firebase部署的设置(Firestore,托管和云功能)位于firebase.json文件中。 Does anyone know a way to have 2 separate firebase.json files - one for test and one for prod ? 有谁知道一种拥有2个单独的firebase.json文件的方法-一个用于测试,一个用于prod Or use variables which are configurable? 还是使用可配置的变量? My project is Angular so my first idea was to use the environments variables which are referenced during the build process - test and prod. 我的项目是Angular,所以我的第一个想法是使用在构建过程中引用的环境变量-测试和生产。 Is this possible? 这可能吗?

My specific goal is to use a different set of firebase.rules for test and production . 我的特定目标是使用一组不同的firebase.rules进行测试和生产 I want to specify a firebase.prod.rules file for example when deploying to production. 我想在部署到生产时指定一个firebase.prod.rules文件。 This technique can be useful for changing firebase indexes file or hosting test vs prod project differences for which there are many configuration options available in the firebase.json file. 这项技术对于更改firebase索引文件或托管test与prod项目之间的差异很有用,因为firebase.json文件中有许多可用的配置选项。

"firestore": {
    "indexes": "firestore.indexes.json",
    "rules": "firestore.rules"
}

You can make a config file and put it in your assests. 您可以制作一个配置文件,并将其放入您的资产中。

From your assests you import it to your ngModule and get the value of the string with the http. 从您的资产中,将其导入到ngModule并使用http获取字符串的值。

After this you build your project and change the config file. 之后,您将构建项目并更改配置文件。 Now change it back for the serve. 现在改回发球区。 And you keep the build config file, never copy it again to the build location. 您将保留构建配置文件,永远不要将其再次复制到构建位置。

Check out Dynamic module/service configuration and AOT for an example. 请查看动态模块/服务配置和AOT作为示例。

public getEnvironment(): Promise<string> { return new Promise<string>(resolve => { let me = this; this.http.get('./config.json') .map(res => res.json()) .toPromise() .then((config) => { resolve(config.url); }); }); }

Your config file look something like: 您的配置文件如下所示:

{"url": ""}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM