4
votes

I searched the docs and couldn't find the answer, does angular-cli's 'environmentSource' file is always loaded no matter what environment i choose? (e.g. prod)

I'm setting my project to work with different env files for dev,staging and prod and wanted to know if this file is always loaded so i can put the general env configurations there.

I'l elaborate, lets say my angular-cli file looks like this:

"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}

and i run the build with --prod, will both "environment.ts" (which is set as the 'environmentSource') and "environment.prod.ts" will be loaded? what i mean is if i have baseUrl in environment.ts but not in environment.prod.ts will i still be able to use baseUrl when running on --prod?

Thanks,

Raz

2

2 Answers

2
votes

The content of the "environments/environment.ts" is used in your code. But when building/serving for a specific environment, the content of that file is replaced dynamically by another environment file if needed.

If you run with the --prod flag, then it means thant environment.prod.ts will overwrite environment.ts. So in your code, you always import environment.ts, but with --prod the content will actually be the one of environment.prod.ts

2
votes

environmentSource will replace environments > source.

find-

"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}

and replace with:

"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}

A new environmentSource entry replaces the previous source entry inside environments.