英文:
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.
{
"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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论