Search code examples
ioscordovaangularionic-frameworkphonegap-build

Building an ionic 2/cordova app on PhoneGap in production mode


CONTEXT

  • I am building a Cordova / Ionic 2 application for iOS.
  • The application is built on PhoneGap build website to generate the ipa.
  • The application is generated successfully and I can launch the application

PROBLEM

I defined some configurations for development and for production using

process.env.IONIC_ENV === 'prod' switch in one of my angular module file. But when i'm running the application, it's clearly running the development configuration.

I also uncompressed and checked the resulting ipa www/build/main.js file and went to look for my environment module.

The snippet that was looking for the environment variable which was originally

useValue: process.env.IONIC_ENV === 'prod' ? ProdEnv : DevEnv

Had been converted to:

useValue: false ? ProdEnv : __WEBPACK_IMPORTED_MODULE_2__environment_dev__

It clearly show me that the preprocessor runned and converted the check into false, which imply that my build is not running with the IONIC_ENV set to 'prod'

QUESTION

How do I make Phonegap build build my iOS application in production mode?


Solution

  • PhoneGap Build builds each native mobile app using the exact code files you give it - there's no concept of "dev" vs. "prod". Based on the reference to "process.env.IONIC_ENV", I'm guessing you're using Ionic's App Scripts to precompile your app. I'm not familiar with them, but based on the available tasks, you'd run: build --prod before uploading the code to PhoneGap Build.

    PhoneGap Build does have an API, so technically you could "make" Build create your app in production mode by using those scripts plus your own to "build --prod" then upload the app via their API.