How to Enable Production Mode in Angular 6, Angular 7 or Angular 8?

How to Enable Production Mode in Angular 6, Angular 7 or Angular 8?

Recently, while working on one of my project, I encountered the following error and I will let you later how actually I fixed it.  This error is basically about angular production mode.

angular is running in the development mode. call enableprodmode() to enable
the production mode.

To enable production mode in Angular 6, Angular 7 or Angular 8, just follow this guide along.  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.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •