If you want to use multiple environment files, here's a guide on how to do it. When building your project, you'll need to specify the configuration you want to use (e.g., prod, test, uat).
To start, add all your configurations in the angular.json file:
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
},
"develop": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.develop.ts"
}
]
},
"release": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.release.ts"
}
]
},
"uat": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.uat.ts"
}
]
},
}
Don't forget to add the corresponding URLs for each file. When building or serving your app locally, make sure to specify the configuration:
ng build --configuration=uat // for uat environment
ng serve --configuration=uat
or
ng build --prod // for production environment
When importing, ensure that you reference it correctly so that the right configuration is applied:
import { environment } from 'src/environments/environment';