在Angular 4中级联环境文件
我正在处理一个包含多个环境文件的angular 4项目在Angular 4中级联环境文件,angular,environment-variables,Angular,Environment Variables,我正在处理一个包含多个环境文件的angular 4项目 环境.前阿尔法.ts 环境.alpha.ts environment.beta.ts 环境生产 这些文件有大量的公共行,如何调用/使用单个公共文件并使用单个特定环境文件来添加唯一行?您可以设置一个预构建任务来创建正确的环境文件 这里有一个想法 将带有公共设置的environment.base.json文件作为json对象 e、 g 创建环境。[envName].json文件,其中每个env文件仅指定匹配环境的特定设置 e、 g 在预构建
- 环境.前阿尔法.ts
- 环境.alpha.ts
- environment.beta.ts
- 环境生产
这些文件有大量的公共行,如何调用/使用单个公共文件并使用单个特定环境文件来添加唯一行?您可以设置一个预构建任务来创建正确的环境文件 这里有一个想法
以下是我们最终所做的: 公共环境
export const commonEnvironment = {
commonVariable1 = "foo",
commonVariable2 = "bar",
}
及
环境生产
import * as common from './commonEnvironment';
export const environment = {
...common.commonEnvironment,
specificVariable1 = "foo",
specificVariable2 = "bar",
}
{
"envName": "prod",
"commonSetting": "common",
"specificSetting": "prodValue"
}
export const environment : any = JSON.parse(JSON.stringify([generatedJsonObjectFromStep3]));
export const commonEnvironment = {
commonVariable1 = "foo",
commonVariable2 = "bar",
}
import * as common from './commonEnvironment';
export const environment = {
...common.commonEnvironment,
specificVariable1 = "foo",
specificVariable2 = "bar",
}