What is the recommended way to build production apps today?

I was wondering what is the recommended way to build ionic2 apps to send to the app stores.

My flow now is:

  • iOS:
    ionic build ios to build the project and then opening it in xcode, archiving, and uploading to Apple
  • Android:
    ionic build android to build the project, then cordova build --release android to build a release version, then use jarsigner to sign the android-release-unsigned.apk, use zipalign to align the apk and finally upload it to Google Play.

Is there a better way?

I have been using app-scripts v0.0.46 but noticed that the newest version builds development versions by default. How do I build production versions after I update?

2 Likes

If you want a cordova app production build, skip this and read @dtslvr’s comment below.
If you want a PWA production build, read on:

In your package.json file, you should have something like this:

"scripts": {
     // ...
     "build:www": "rm -rf www && ionic-app-scripts build --prod",
     // ...
},

Now in your terminal run:

npm run build:www

You are done. This will enable production mode in angular2 with tree-shaking, AoT, etc and build your app in the folder www ready for you to serve in production.


Valid as of ionic2-rc5.
Get more detailed info on the available ionic scripts and what they do over here.

7 Likes

I think with app-scripts 0.0.47 you just need to pass the --prod flag to enable AoT/uglify, so e.g. ionic build android --prod. Everything else is the same.

1 Like

ionic build android --prod produces the file android-debug.apk (3.4Mb) and
ionic build android --release generates the file android-release-unsigned.apk (4.1Mb)

Which of these is the right one to release?

4 Likes

You want both --prod and --release. --prod is for ionic-app-scripts, affecting the generated JavaScript code; --release is for Cordova, affecting the Android app itself. You also need to sign the Android apk before publishing it.

4 Likes

Thanks @mirkonasato.

tldr; ionic build android --prod --release for a production release.

6 Likes

Just an addition, for Ionic 2.2.1, to build a production ready PWA, you may run this command:

npm run build --prod

Documentation is provided here: https://github.com/driftyco/ionic-app-scripts

1 Like

Use ionic build android --prod --release --keystore="your.keystore" --storePassword=your_password --password=your_password --alias="your_alias". Though, I’m not seeing a difference in load time, both at 16 seconds. =(

1 Like

try
npm run build —aot
then
ionic build android --prod --release
then
ionic run android --prod

my app is loading now in 5sec.before it was 13sec.
Let me know if yours also working…

1 Like

The problem was a bug in the ionic-cli. I upgraded it to the very latest version and it works now.

Can i decrease boot time from 5sec to less than 1sec in android@6.1.1. is that possible,what else i need to do to load my app fast.

I think 5 seconds is already pretty good. For android <= 5.0, you can use something called Crosswalk.

When i install app it takes 5 to 6sec to open.But when in reopen is also takes 5sec,is this the behaviour of android or my app is lacking something to load again.i my console it shows device ready not fired after 5sec msg also.

No it seems like your app is crashing. The app should be running in the background. You can double tap on the Home key (the key most far from your “Back” key). You should see your app in the background, still opened. If not, it crashed or you’re closing the app somehow.

I see the app in background, when i tap on it from home key, it again loads and takes 5 secs.

If your device is RAM restricted, the OS may be terminating the app when switching to home-screen. If your device is storage-space restricted then similar problems can occur.

Either way, your replies are somewhat getting out of topic and there’s not much more we could advise that isn’t said many times already.

i added this line to package.json and got : “missing script: build:www”

Just in case for windows users instead of:

rm -rf www

use

rd /s /q www
3 Likes

Works the opposite for me. ionic build android --prod produces a bigger file and I was not able to sign the generated android-dbug.apk using jarsigner.

You should upgrade to a more recent CLI, 3.x has been out for months. There the command will be ionic cordova build android --prod.