Vingtoft
Vingtoft

Reputation: 14586

Angular | Start Test Server with Production Environment Variables

Im developing an Angular 6 application using CLI 6.0.5.

I have two files with environment variables:

environments.ts and environments.prod.ts.

When I build for production (ng run build --prod), the production variables are used. Running test server (npm start) uses test variables.

Question: How can I run test server with production variables?

Upvotes: 0

Views: 1518

Answers (2)

user4676340
user4676340

Reputation:

You are meddling your commands a little. Let's recap :

npm start

Runs the start command declared in your package.json

ng run build --prod

Doesn't exist (that I know of). It's either ng build --prod or npm run build -- --prod

Now, if you want to use different environments, the command is

ng serve --env prod 
ng serve --configuration prod

The former is for Angular < 5, the latter is for Angular 6.

To be sure that you run the good command, simply run

ng serve --prod

This will run in production mode, which can be set up in your angular[-cli].json file.

You of course have to declare those environments/configuration in your angular[-cli].json file.

Upvotes: 1

Nasiruddin Saiyed
Nasiruddin Saiyed

Reputation: 1466

You can change environment using --prod option while running it with angular cli. This is the link for its doc you can refer for more options.

ng serve --prod 

Happy Coding!!

Upvotes: 1

Related Questions