Skip to main content

Angular Budgets

Budgets set size limits on your build output. Angular warns or fails the build when a bundle exceeds the threshold, preventing accidental bloat from creeping in unnoticed.

Configuration (angular.json)

"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kb",
"maximumError": "8kb"
}
]
}
}

Budget Types

TypeWhat it measures
initialJS + CSS loaded on the initial page (most important)
lazyAny lazy-loaded chunk
allScriptSum of all JS scripts
anyScriptAny single JS file
anyAny single output file
anyComponentStyleThe inline styles of a single component

Warning vs Error

LevelBehaviour
maximumWarningBuild succeeds, warning printed
maximumErrorBuild fails — CI pipeline blocked

Set maximumWarning conservatively so you catch drift early. Set maximumError as the hard cap.

Analyzing What's Inside the Bundle

When a budget is exceeded, find the culprit:

# Step 1: generate the stats file
ng build --stats-json

# Step 2: visualize it
npx webpack-bundle-analyzer dist/my-app/browser/stats.json

Common causes of oversized bundles:

  • Importing an entire library instead of specific functions (import * as _ from 'lodash')
  • A large third-party dependency loaded eagerly instead of lazily
  • Duplicate dependencies (different versions of the same package)

Quick Fixes

// ❌ Imports the whole library (~70 kb)
import * as _ from 'lodash';

// ✅ Tree-shakeable — only what you use
import { debounce } from 'lodash-es';
// ❌ Eager — increases initial bundle
import { ChartModule } from 'chart.js';

// ✅ Lazy — loaded only when needed
const { Chart } = await import('chart.js');
App typeinitial warninginitial error
Landing / marketing150 kb250 kb
Standard app400 kb800 kb
Feature-rich dashboard600 kb1 mb

Configure budgets at project creation — retrofitting them on a large app is painful.