Managing large amounts of environment variables
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 14 giờ 23 phút
- Pull request đã merge (30 ngày)
- 162
Mô tả
### 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_
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với issue trước đó #4318 và các entry point của các lệnh build, serve, test và e2e. Xem xét cách tiếp cận hiện có trong environments.ts và ví dụ DefinePlugin trong webpack.config.js, sau đó xác định cách các biến được export hoặc tệp .env nên được cung cấp dưới dạng process.env.VARIABLE. Được coi là hoàn thành khi hành vi được hỗ trợ và phạm vi áp dụng cho các lệnh này được xác định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript, webpack
- Lĩnh vực
- build-system, cli
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100