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

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

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.

{
  "projects": {
    "<project>": {
      "architect": {
        "build": {
          "configurations": {
            "user": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.user.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "configurations": {
            "user": {
              "browserTarget": "<project>:build:user"
            }
          }
        }
      }
    }
  }
}

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.

{
  &quot;projects&quot;: {
    &quot;&lt;project&gt;&quot;: {
      &quot;architect&quot;: {
        &quot;build&quot;: {
          &quot;configurations&quot;: {
            &quot;user&quot;: {
              &quot;fileReplacements&quot;: [
                {
                  &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
                  &quot;with&quot;: &quot;src/environments/environment.user.ts&quot;
                }
              ]
            }
          }
        },
        &quot;serve&quot;: {
          &quot;configurations&quot;: {
            &quot;user&quot;: {
              &quot;browserTarget&quot;: &quot;&lt;project&gt;:build:user&quot;
            }
          }
        }
      }
    }
  }
}

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:

确定