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?
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.
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.
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.