Managing large amounts of environment variables

未关闭
#28,661 21 条评论 38 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

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

调研方向

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

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

描述

area: @angular/build feature feature: under consideration
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 <define> <define> <define>....
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:

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

主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
16 小时 35 分钟
30 天内合并 PR
176

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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