AOT Compilation is not obvious for new users


#1

When using Ionic 3 running npm run build does not do AOT compilation and running ionic-app-scripts build --prod also doesnt work as it isnt installed globally. It requires modifying your package.json to add to the scripts section a line of:

"prod": "ionic-app-scripts build --prod",

Then you can run:
> npm run prod

This will achieve a nicely optimized set of assets in the www folder that can be distributed as a web app.

But, this isn’t obvious to new users.

Could we get a production build option like this added by default to new projects and documented?


#2

Or you could just run ionic build android/ios --prod. It’s embedded in the ionic CLI and runs with AOT compilation.


#3

That works for cordova ios/android but when targeting the web - not so much.


#4

ionic build works just fine for me. What is your problem with it?


#5

Could be a good point.

You can’t provide --prod to npm run build?
Also what @rapropos posted - is this different?


#6

So ionic build ios works if you are on a mac but not windows and intend to target ios
ionic build android works if you have android studio installed and intend to target android
But it looks like npm run build --prod does work to produce an AOT web build.

I couldn’t find that in the docs anywhere Sujan12 so thanks very much for sharing. Some docs or adding something obvious like ionic build web would be a handy addition.


#7

Ionic CLI (the code behind calling ionic on the command line) is being rewritten right now and the iOS and Android build commands will be moved to ionic cordova build ... to make it clear, that this is for more than a normal “build /src to /www”.

I’m not sure what will happen to the normal build, if you have to use npm run build etc- but this topic here made it clear that there is room for improvement. Hope the next beta of the CLI will work on that, if not we’ll have to open some issues on Github.


#9

We’re working on a cheat sheet to help people understand the command translations from v2 -> v3 of the Ionic CLI.

As soon as it is in a fit state to share, I’ll share it here, a tweet, and send out a message on Ionic Slack Worldwide channel.


#10

And here you go, a cheat sheet for migrating from the Ionic CLI v2 -> v3

This covers the “major” use cases, for all else, developers can use ionic help <command>.

https://docs.google.com/document/d/1r8nTAaJ5hLIJ1DCwBozU-JGV480Du0xCMIg2dj3JRQo/edit?usp=sharing


#11

So no ionic command for a npm run build (--prod) equivalent that does a non-Cordova build?


#12

Why not just use npm run build ?


#13

See OPs post: Because it is not obvious, it is not mentioned in documentation.


#14

npm run build doesnt do AOT compilation. npm run build --prod does. The ionic cli doesn’t have a command that does this so you need to do some digging to work that out. On top of that the obvious thought process you may go through from the cheat sheet is that you want to build for the web/browser platform, however if you run ionic cordova build browser it does an extremely long running experimental cordova build (see https://www.raymondcamden.com/2014/09/24/browser-as-a-platform-for-your-phonegapcordova-apps/). So, the topic is to make it simple and obvious what to do to build your ionic app for running in the browser.