'In Ionic 4, how can I detect if I'm running in debug vs prod?

In Ionic 3, you could tell if it was installed on a device by using

if (!(<any>window).cordova)
    isDebug = true;

This doesn't appear to work in Ionic 4. This always comes back as false.

What is the preferred method to detect if it's a debug vs a production build?



Solution 1:[1]

environments/environment.prod.ts

export const environment = {
    production: true
};

environments/environment.ts

export const environment = {
    production: false
};

Your page

import { Platform } from '@ionic/angular';
import { environment } from './environments/environment';

@Component({...})
export MyPage {
  constructor(public platform: Platform) {
     if(platform.is('cordova')) {
        console.log('cordova');
     }
     console.log(Prod? ', environment.production);
  }
}

Commands

ionic build --prod // Prod? true
ionic build // Prod? false
ionic s // Prod? false
ionic s --prod // Prod? true

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Remi Sture