DEV Community

Cover image for Angular 15: what happened to environment.ts

Angular 15: what happened to environment.ts

Gianpiero Errigo on January 27, 2023

TL;DR: Nothing! Angular 15 simply doesn't ship anymore environment files by default. You can still create them and configure their repla...
Collapse
 
jdgamble555 profile image
Jonathan Gamble

Angular needs to get rid of this and add .env support out of the box IMHO. Globals are something else.

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Hi jonathan.
How would you like dotenv to be integrated natively in Angular?

Collapse
 
jdgamble555 profile image
Jonathan Gamble

Good question. I'm not sure, but it is in all other frameworks. It works with the Webpack version of Angular, but that is overkill just for env variables. At the very least, it should work natively with Universal.

Thread Thread
 
gianpiero_errigo profile image
Gianpiero Errigo

I got no experience with dotenv or Universal, so maybe I'm missing something basic:
what issue do you face if you try to prepone a script loading the .env, inside build script of your package manager?

Thread Thread
 
jdgamble555 profile image
Jonathan Gamble

It doesn't work. Here is just one article on how to hack it - indepth.dev/tutorials/angular/inje...

Thread Thread
 
gianpiero_errigo profile image
Gianpiero Errigo

Right.
Now I get it.
That really old ticket linked in the article suggests a lot of solutions, but looks like none of them has still been accepted and integrated into cli.

Collapse
 
frederikprijck profile image
Frederik Prijck

Nice article! Thanks for the mention! β™₯️

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo • Edited

Thanks to you.
Your post has been really useful.

Collapse
 
yogeshk05 profile image
YogeshK05

Really a good articleπŸ™Œ! One stop solution for all the information one might need about the topic.

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Thanks.
I'm glad it's been helpful for you.

Collapse
 
ptletski profile image
ptletski

It's strange how a "highly-opinionated" framework like Angular will suddenly punt on its "highly-opinionated" solution. Their solution provided convenience (as does their whole product). Why use their framework, if not for convenience? God knows it's hard enough to use as it is.

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Hi ptletski.
Not sure I get where's the ambiguity.
The choice of environment files in the beginning was forced by circumstances.
Once those were gone, they dropped default use of the files.
In this case, the whole setup was not due to opinion, but to necessity.

Collapse
 
julgon2012 profile image
Julio πŸ‘Ή

why does angular put us in the trouble of replacing environments when they were so easy to use? What a desire to annoy the user!
How do I know, in the application, what build mode I am in?

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Hi Julio.
None has been obliged to use a different system.
As explained in the article, old environment files replacement per-build works as usual, and since 15.2 they can be even generated on demand with a schematic.
The reason for them not being default anymore is the point of the whole article. :-)
About the last question, I'm not sure if I get it: why should you care about the build mode you're in?