I’m trying to understand how angular 2 environment works in ionic 2. There is no call to enableProdMode() in ionic 2 app so I suppose angular 2 would work in dev mode. The question is when the app is built, would the app automatically get built in prod mode or it has to be managed by developer?
I also checked ionic help serve and ionic help build there isn’t an option for environment.
My concern is that I don’t want my app gets built in dev mode, that may impose a performance loss big or small.
export class MyApp {
rootPage: any = HomePage;
constructor(platform: Platform) {
if (platform.is('ios')
|| platform.is('android')
|| platform.is('windows')) {
enableProdMode();
}
}
Results in
ORIGINAL EXCEPTION: Cannot enable prod mode after platform setup.
ionicBootstrap(MyApp, [], {prodMode: true}); works of course, but it’d better to activate prod mode only when the app is running on a device since dev mode can be useful during development.
Angular 2’s cli can trigger prod mode from the command line
is exactly what I would expect like you said it is the way angular-cli is doing it. Checking the device is a workaround that helps for most but not all cases.
Feel like I’m going crazy. ionic serve --prod still gives me false for environment.production. In the console it also says Angular is running in the development mode. Call enableProdMode() to enable the production mode.
Thanks for the response. I haven’t played around with my app on the iOS simulators or on an actual device yet. Main reason being the iOS simulator makes my animations (the default ones, like opening a modal) really slow and I haven’t figured out how to view the console logs yet. Strange thing is the comment that used ionic serve had 4 votes, so I thought it was just me.
run “ionic serve --prod” still give me “Angular is running in the development mode. Call enableProdMode() to enable the production mode.”.
Is it need to run “enableProdMode();” manually?
Just found an article, add two line in main.ts to enable it into production mode.
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {enableProdMode} from '@angular/core';
import { AppModule } from './app.module';
// this is the magic wand
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);