Precompile Components with AOT
Use Angular's Ahead-of-Time (AOT) compilation to precompile components, reducing runtime compilation overhead and improving startup performance.
// main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from './app/app.module.ngfactory';
// Enable production mode if in production
if (process.env.NODE_ENV === 'production') {
enableProdMode();
}
// Bootstrapping the AppModule using AOT compiled factory
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory)
.catch(err => console.error(err));
This is the main entry point of an Angular application which has been AOT compiled. The AppModuleNgFactory is imported, which is the AOT compiled version of the AppModule. If the application is in production mode, Angular's production mode is enabled to disable assertions and other checks within the framework. Then, the platformBrowser is used to bootstrap the application using the AOT factory.