# Example: Generate a production build with Angular CLI
ng build --prod
# Example: Analyze bundle sizes using Webpack Bundle Analyzer
npm install --save-dev webpack-bundle-analyzer
ng build --prod --stats-json
npx webpack-bundle-analyzer dist/stats.json
# Example: Install and use Source Map Explorer
npm install -g source-map-explorer
source-map-explorer dist/main.<hash>.js
// Example: Lazy load a module in your route configuration
const routes: Routes = [
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
];
// Example: Configure lazy loading in your application
@NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }
// Example: Eliminate shared module imports if not needed
@NgModule({
imports: [CommonModule, SharedModule],
declarations: [SomeComponent]
})
export class FeatureModule { }
// Example: Specify bundle size budgets in your Angular.json file
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}