What does --prod flag do exactly?

Does it include the four Advanced Options? What does it do, exactly?

$ ionic build --help

➜  imoto-motoboys git:(master) ✗ ionic build --help

  ionic build - Build web assets and prepare your app for any platform targets

    ionic build will perform an Ionic build, which compiles web assets and prepares them for deployment. For
    Ionic/Cordova apps, the CLI will run cordova prepare, which copies the built web assets into the Cordova platforms
    that you've installed. For full details, see ionic cordova prepare --help.

  Usage:

    $ ionic build [options]

  Options:

    --prod ................... Build the application for production

  Advanced Options:

    --aot .................... Perform ahead-of-time compilation for this build
    --minifyjs ............... Minify JS for this build
    --minifycss .............. Minify CSS for this build
    --optimizejs ............. Perform JS optimizations for this build
1 Like

--prod flag minimizes and optimizes your entire project to a single file depending on type.
It also ignores plugins/imports which you have included but haven’t used.

Example -
All *.ts files gets compiled first and then all gets minified in a single file (main.js).
Similarly with ‘*.scss’ file too. They also get minified into a single file (main.css).

By doing this, you can publish your project for world without allowing users to easily inspect and copy codes from your project.

Also, there is a flag --release which you should use along with --prod to remove debuggabe flag from generated apk or ipa file.

3 Likes

Thanks @sujit77, great explanation!

These are the commands I’m using to release, are some of these flags redundant/unnecessary?

"build:ios": "ionic cordova build ios --prod --release --aot --minifyjs --optimizejs --minifycss",
"build:android": "ionic cordova build android --prod --release --aot --minifyjs --optimizejs --minifycss",
2 Likes

As of app-scripts 3, building with --prod means building with those 4 advanced options, and also the Angular ngo tool (ngo short for Angular Optimization).

1 Like

I think you only require -

ionic cordova build ios/android --prod --release

Not much sure about --aot, does it gives extra performance benefit?

@sujit77 https://angular.io/guide/aot-compiler

The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code.

That’s all I know :slight_smile:

@AaronSterling, thank you sir

1 Like

–prod tags include --aot --minifyjs --minifycss and --optimizejs. You can look at the documentation

3 Likes

–prod already invokes aot