In Ionic 3, I could use this code to check if I was running on a device or in a browser:
if ((<any>window).cordova)
this.debug = false;
The if ((<any>window).cordova)
always returns false in Ionic 4.
How can I check if I’m in debug mode?
Check the current Platform
This doesn’t work.
If I’m testing on Chrome as iPhone, using platform.is("ios")
returns true.
I was hoping to be able to use angular environments, but it appears that the Ionic Pro build doesn’t use ng build --prod
. Just ng build
. So environment never gets switched to prod.
maybe for chrome on ios
if (platform.is("ios") && !platform.is("cordova")) {}
about build environment maybe the chapter “Build environments” https://ionicframework.com/docs/pro/builds/ could give a hint
Thanks! Those links did lead me to the right solution.
Basically, the Ionic Pro build will use whatever is in your package.json. Mine had this:
"scripts": {
"build": "ng build"
},
I changed it to this:
"scripts": {
"build": "ng build --prod",
},
Which gave me the correct environment variable.
2 Likes