“User Custom environments in Angular” can be translated as “Angular中的用户自定义环境”.

huangapple go评论113阅读模式
英文:

User Custom environments in Angular

问题

在我们的Angular项目中,我们有一个environment.ts和environment.prod.ts

我想要的是也有一个environment.user.ts
只有在配置了变量的情况下才会覆盖它们,以便测试人员/开发人员可以更轻松地个性化覆盖一些配置。

我想知道是否有一种通用的模式,也许通过库导入或一种方便的常见方法来实现。或者也许所有人都一遍又一遍地重新发明轮子。

英文:

In our angular project we have an environment.ts and environment.prod.ts

What I would like is to also have a environment.user.ts
Which would overide only variables if they are configured so testers/developers can more easily overide some configs personally.

I wonder if there is a generic pattern for this maybe by library import or a handy common way to do it.
Or perhaps do all people reinvent the wheel over and over

答案1

得分: 0

Yes you can specify other build configurations in angular.json. It should be fairly obvious how if you look at the existing ones in there.

  1. {
  2. "projects": {
  3. "<project>": {
  4. "architect": {
  5. "build": {
  6. "configurations": {
  7. "user": {
  8. "fileReplacements": [
  9. {
  10. "replace": "src/environments/environment.ts",
  11. "with": "src/environments/environment.user.ts"
  12. }
  13. ]
  14. }
  15. }
  16. },
  17. "serve": {
  18. "configurations": {
  19. "user": {
  20. "browserTarget": "<project>:build:user"
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. }

Documentation here: https://angular.io/guide/workspace-config#alternate-build-configurations

英文:

Yes you can specify other build configurations in angular.json. It should be fairly obvious how if you look at the existing ones in there.

  1. {
  2. &quot;projects&quot;: {
  3. &quot;&lt;project&gt;&quot;: {
  4. &quot;architect&quot;: {
  5. &quot;build&quot;: {
  6. &quot;configurations&quot;: {
  7. &quot;user&quot;: {
  8. &quot;fileReplacements&quot;: [
  9. {
  10. &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
  11. &quot;with&quot;: &quot;src/environments/environment.user.ts&quot;
  12. }
  13. ]
  14. }
  15. }
  16. },
  17. &quot;serve&quot;: {
  18. &quot;configurations&quot;: {
  19. &quot;user&quot;: {
  20. &quot;browserTarget&quot;: &quot;&lt;project&gt;:build:user&quot;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. }

Documentation here: https://angular.io/guide/workspace-config#alternate-build-configurations

huangapple
  • 本文由 发表于 2023年6月15日 05:47:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定