How to enable the "productio.mode" in angular2 with Angular-cli?

2

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 result of printing on the log is:

environment.production:false

How would the environment variable for production be enabled?

    
asked by Pablo Ezequiel 18.03.2017 в 23:32
source

3 answers

2
ng build --target=production --environment=prod

You can expand the info here: link

You can also do:     ng serve --environment = prod To test in local

    
answered by 19.03.2017 / 01:53
source
1

Add the following entry in your angular-cli.json file:

"environments": {
  "prod": "environments/environment.prod.ts"
}

Create a folder called environments where you should have the following code:

export const environment = {
  production: true
};

And compile it with:

ng build --prod
    
answered by 08.04.2017 в 05:13
0

In angular-cli it is already configured in the src / environments directory.

In the environment.ts file, you should have the following:

export const environment = {production: false}

You just have to change it as follows:

export const environment = {production: true}

And you already have production mode activated.

    
answered by 01.05.2017 в 12:23