When a new project is created with angular-cli by default it is not enabled to run in productio.mode. How can it be enabled?
The generated main.ts file is as follows:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
console.log("environment.production:" + environment.production);
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
And the print result in the log is:
environment.production:false
How would the environment variable be enabled for production?
You can expand the info here: https://github.com/angular/angular-cli/wiki/build
You can also do: ng serve --environment=prod To test locally
Add the following entry to your angular-cli.json file :
Create a folder called environments where you should have the following code:
And compile it with:
In angular-cli it is already configured in the src/environments directory .
In the environment.ts file you should have the following:
You just have to change it to as follows:
And you already have the production mode activated.