Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable production mode in angular 2

I have been creating web application using Angular 2 and Firebase, I want to enable production mode.

main.ts

if (environment.production) {
  enableProdMode();
}

environment.ts

export const environment = {
  production: true
};

environment.prod.ts

export const environment = {
  production: true
};

Then I'm tried ng build -prod; ng serve ,but still not working.

Thanks in advance.

like image 289
naruto Avatar asked Apr 24 '17 19:04

naruto


People also ask

How do I know if angular is running in prod mode?

Simply check the production variable present in the environment file, it will be true for production mode and false for development.

What is enableProdMode ()?

enableProdModelink function. Disable Angular's development mode, which turns off assertions and other checks within the framework.

What is development mode and production mode in angular?

Development build produces source map files whereas production builds not. Source map files help us easily debug our application even after the files are compressed and compiled.

What is production mode?

Production Mode​ The Production Mode of the project is where you have access to the finalized version of your data models & datasets that are ready for end-users to explore and build reports. You cannot make changes to project files when you are on Production Mode.


1 Answers

ng serve --prod didn't worked for me.

This worked btw 😊

ng serve --configuration=production

it creates a test production server which works same as it works on the deployed one. I tried this testing with environment.js (all other solutions didn't worked for me)

You can follow this (Becoming an Angular Environmentalist) article to learn more about Angular environments

like image 129
Kavinda Jayakody Avatar answered Sep 29 '22 18:09

Kavinda Jayakody