angular / angular/angular-cli

Managing large amounts of environment variables

未关闭
#28,661 21 条评论 38 个 reaction 已指派 0 人 在 GitHub 查看
area: @angular/build feature feature: under consideration
主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
14 小时 23 分钟
30 天内合并 PR
162

描述

### Command

build, serve, test, e2e

### Description

I am reopening https://github.com/angular/angular-cli/issues/4318.

Essentially we need a way to pass environment variables to the build/serve commands. environments.ts file is not a viable solution as you would need to end up with hundreds of environment.ts files depending on all the permutations per environment.

The solution to https://github.com/angular/angular-cli/issues/4318 also does not address this since you need to know the `define` values when running the command `ng build ....`
Which means you would have to generate the build command same way as generating the `environment.ts` file.

Most enterprise angular applications I have worked on ends up extending the `webpack.config.js` file adding:
```javascript
DefinePlugin({
process: {
env: {
VAR_1: JSON.stringify(process.env.VAR_1),
...
}
}
})
```

This issue has been brought up for years with the Angular repo but i've never seen a resolution so I want to try to make it as clear as possible.
We should support a `dotenv()` style solution where in the code we can use `process.env.VARIABLE`.
In the build machine we can either:
`export VARIABLE=test`
or have a `.env` file to pick it up.

This is supported by pretty much every other framework out there so I'm not sure why it wouldn't be possible or hasn't already been implemented.

If the issue is the angular team doesn't want this behaviour then that is fine but I am looking for a yes/no type answer. If the answer is no the angular team would be able to point to this issue for all future feature requests of this nature.

### Describe the solution you'd like

_No response_

### Describe alternatives you've considered

_No response_

贡献指南

打开贡献指南

调研方向

从之前的 issue #4318 以及 build、serve、test 和 e2e 命令的入口点开始。检查现有的 environments.ts 方案和 webpack.config.js 中的 DefinePlugin 示例,然后确定应如何将导出的变量或 .env 文件作为 process.env.VARIABLE 暴露出来。当这些命令支持的行为和范围都已定义时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript, webpack
领域
build-system, cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。