natchiketa / angular-cli-envvars

Example project for my article "Angular CLI and OS Environment Variables"
55 stars 12 forks source link

QUESTION: how you detect which environment.__NAME__.ts you should import. #2

Open rodriggochaves opened 6 years ago

rodriggochaves commented 6 years ago

I just read your post on Medium. Great post!

I tried to use your solution. But a problem / question showed up: how you import the environment constant in your files? I search your repository and you use this:

import { environment } from '../../../environments/environment';

But in the post you said to change environment.ts to enviroment.dev.ts. The script set-env.ts configure this creating a copy of current environment.__NAME__.ts?

Thanks in advance!

gldraphael commented 6 years ago

You only need to reference the environment.ts file. Angular takes care of using the right file. Here's a related post.

Javarome commented 5 years ago

how do you detect which environment.NAME.ts you should import?

Angular CLI does it, depending on the configuration parameter you run when building (ng build --configuration=production for instance ; in such a case Angular CLI will use environments/environment.prod.ts) By default development is assumed, which implies no suffix.

how you import the environment constant in your files?

This is the work of set-env.ts, which overwrites the relevant environments/environmentXxx.ts file which the OS env variables inserted inside thanks to the dotenv node lib.