The Angular compilation process transforms your Angular templates and components into efficient JavaScript code that the browser can execute. Over time, Angular has evolved from the View Engine compiler to a newer, more efficient system called Ivy.
Here's a breakdown of the differences between View Engine and Ivy, and how each affects the compilation process:
π§ 1. What Is Angular Compilation?
Angular templates (HTML inside components) are not regular HTML—they include Angular-specific syntax like *ngIf, {{ }} interpolation, and custom directives. The compiler translates these templates into JavaScript instructions that render and update the DOM.
Angular uses Ahead-of-Time (AOT) or Just-in-Time (JIT) compilation modes:
-
JIT: Compiles in the browser at runtime (used in development).
-
AOT: Compiles at build time into efficient JS (used in production).
π§± 2. View Engine (Legacy Compiler)
➤ Used in Angular versions < 9
π How It Works:
-
Compiles templates into intermediate representations.
-
Generates separate factory files (
.ngfactory.ts) during AOT. -
Produces larger bundles due to metadata duplication.
-
Slower build and recompilation times.
𧨠Drawbacks:
-
Complex internal architecture.
-
Poor tree-shaking — unused code often bundled.
-
Hard to debug and understand compiled output.
-
Limited support for dynamic components.
πΏ 3. Ivy (Modern Compiler and Runtime)
➤ Default since Angular 9
π How It Works:
-
Compiles components into efficient JavaScript instructions directly (no
.ngfactory.tsfiles). -
Uses incremental compilation, so only changed components are recompiled.
-
Supports locality — each component is compiled independently.
✅ Benefits:
-
Smaller Bundle Sizes – Thanks to better tree-shaking and no duplicate metadata.
-
Faster Builds – Especially during incremental compilation.
-
Better Debugging – Compiled output is easier to read.
-
Improved Dynamic Components – Supports lazy loading of individual components, not just modules.
-
Backward Compatible – Works with libraries compiled with View Engine.
⚖️ Comparison: Ivy vs. View Engine
| Feature | View Engine | Ivy |
|---|---|---|
| Compilation Strategy | Global | Local (per component) |
| Tree-Shaking Efficiency | Limited | Excellent |
| Bundle Size | Larger | Smaller |
| Build Performance | Slower | Faster (especially rebuilds) |
| Debugging | Difficult | Easier |
| Dynamic Component Support | Limited (factories required) | Native support |
| Default in Angular Versions | Angular < 9 | Angular 9+ |
π Why Ivy Matters Today
Ivy enables more efficient, modern Angular apps with better tooling, smaller bundles, and easier debugging. It's also a foundation for future Angular features like standalone components and improved hydration for SSR.
