How to Enable Production Mode in Angular 6?

How to Enable Production Mode in Angular 6?
Rating: 5 - 1 Votes

How to Enable Production Mode in Angular 6?

By default, in your Angular Project’s main.ts file, you will have this following code:

The above code clearly importing environment.ts file and checking if its property production is set to false or true and by default it is always false since you want to look out for errors, warning etc during development.

But there is one more file environment.prod.ts and there production property is set to true.
These 2 files come into play when you are building your app using following command:

ng build

So when you run above command, Angular will build your project depending upon the properties also known as settings defined in the environment.ts

To build your project for production, you have to make use of following command.

ng build –env=prod

You have to set environment flag (–env) to production to get your production build.