If you’re not using Angular CLI (Command Line Interface) for your Angular apps, then you’re missing out on a tool that will make your life a lot easier.
Angular CLI can kick–start a project quickly by setting up a modest application foundation with a component example that works right out of the box. Among other things, it also makes it quick and easy to run a development server and optimize production builds. Production builds can be done without Angular CLI, but it’s so much easier with it.
Why are production builds important? They make your app load and run much faster, which reduces bandwidth costs and improves the user experience — so you should definitely be using them.
With angular CLI, simply pass “-prod” to your “build” command and viola, you’ve got a production build. With a production build, compilation happens at build time, which means the Angular compiler doesn’t need to be deployed with your application, making it much smaller. You’ll also get better type and error checking before you deploy.
There are many options for the build command, but I’ve taken a real (medium sized) application and compiled some benchmark metrics for a few of the popular build options to illustrate their affect on our application.
|Build Mode||Artifact Size (gzip)||Build Time||Initial Load Time||Boostrap Time||Time to First Display|
|ng build||4.2 MB||21 s||16.2 ms||936.7 ms||952.9 ms|
|ng build –aot||4.00 MB||42 s||18.2 ms||494.4 ms||512.6 ms|
|ng build -prod||2.66 MB||49 s||21.6 ms||493.4 ms||515.0 ms|
I should mention that build time and bootstrap time will vary with computer speed, and load time will vary with internet connection speed, so don’t worry too much about the specific numbers — pay attention to the deltas because these relative numbers give us insight into where the work is happening in these different builds.
We can see that going from a standard dev build to a full production build, a significant part of the work shifts from the user’s computer to the build time. The artifact size is not really important during development time since it’s being loaded from a local disk, and half a second of bootstrap time isn’t a big deal either. But these two metrics are nearly cut in half when switching to production mode, and the production build takes 2.5 times longer, but that’s a one time cost for the deployment team and a marginal one at that.
Take the time to make a proper production build; as we can see, the user gains a lot from a real production build.