Curious Minds

Clear answers to science and history questions

Which build tool does Angular use?

· 4 min read · Science

Angular uses Webpack as its default build tool, accessed through the Angular CLI.

Quick answer: Angular CLI runs Webpack behind the scenes.

Rule of thumb: ng build → Webpack.

Default Build Tool

When you create a project with ng new, the CLI adds a package called @angular-devkit/build-angular. That package contains a pre‑configured Webpack configuration file. The CLI never exposes the raw Webpack config; instead it merges user options with its internal defaults and then launches Webpack to bundle the application.

Webpack performs the classic tasks of module resolution, tree‑shaking, asset handling, and code splitting. Angular’s own compiler (the Ivy compiler) runs as a loader inside the Webpack pipeline, turning TypeScript and Angular templates into JavaScript that Webpack can bundle.

Because the build process is hidden, most developers interact only with the CLI commands ng build, ng serve, and ng test. Each of those commands ultimately invokes Webpack with a set of flags derived from the project's angular.json configuration.

CLI Invocation Details

The ng executable reads the workspace configuration file angular.json. Under the projects → your‑app → architect → build → options node you will find keys such as outputPath, assets, styles, and scripts. When you run ng build, the CLI translates those options into a Webpack configuration object.

Key translation steps include:

  • Entry point: The CLI sets src/main.ts as the Webpack entry.
  • Loaders: ts-loader is replaced by Angular’s @ngtools/webpack loader, which runs the Ivy compiler.
  • Plugins: The DefinePlugin injects environment variables, and the MiniCssExtractPlugin extracts CSS into separate files.
  • Optimization: Production builds enable minification, dead‑code elimination, and bundle splitting based on lazy‑loaded routes.

After constructing the configuration, the CLI calls Webpack’s Node API. The process runs in a child process, streams logs to the console, and writes the final bundles to the folder defined by outputPath (by default dist/your‑app).

Customizing the Build

Although the CLI hides the raw Webpack file, you can still influence the build through several mechanisms.

angular.json overrides

Within angular.json you can add or replace options such as fileReplacements, budgets, and outputHashing. These options map directly to Webpack features like aliasing, bundle size warnings, and cache‑busting filenames.

Custom Webpack Config

For advanced scenarios you may install a community package like @angular-builders/custom-webpack. That package lets you supply a webpack.config.js file that the CLI merges with its internal configuration. Typical use cases include adding a new loader for a non‑standard asset type or tweaking the optimization settings.

Environment Files

The CLI replaces files listed under fileReplacements based on the build configuration (development vs production). This mechanism is often used to swap environment.ts with environment.prod.ts, allowing you to change API endpoints or feature flags without touching the Webpack config.

Remember that any custom Webpack changes are applied after the default configuration, so you rarely need to duplicate core Angular loader settings.

Alternative Build Tools

While Webpack is the default, the Angular ecosystem supports other bundlers. Projects that prefer a faster, less configuration‑heavy tool can switch to Vite, esbuild, or Rollup, but doing so requires abandoning the Angular CLI’s built‑in commands.

To use an alternative, you typically generate a plain TypeScript project (without @angular-devkit/build-angular) and then set up the chosen bundler manually. The steps involve:

  • Installing the bundler (e.g., npm install vite).
  • Creating a configuration file (vite.config.ts) that includes the @angular/compiler-cli plugin for Ivy compilation.
  • Replacing ng build scripts in package.json with the bundler’s build command (e.g., vite build).

Because the Angular compiler is tightly integrated with the CLI’s Webpack pipeline, you must add the @angular/compiler-cli plugin manually. The community maintains plugins such as vite-plugin-angular to simplify this process.

Switching away from Webpack forfeits automatic support for features like differential loading, built‑in service‑worker generation, and the Angular DevKit’s schematic utilities. Evaluate the trade‑off based on build speed requirements and the need for custom asset pipelines.

Verifying the Build Process

To confirm that Webpack is being used, you can inspect the console output of ng build --verbose. The CLI prints a line similar to “Running Webpack …” followed by the version number. Alternatively, check the generated dist/your‑app folder for files named main.{hash}.js and runtime.{hash}.js; those naming conventions are produced by Webpack’s output.filename pattern.

If you have added a custom Webpack config via @angular-builders/custom-webpack, the build log will also list “Using custom webpack config” and display the path to your config file. Any errors that reference webpack modules (for example, “Cannot find module 'webpack/lib/Chunk'”) further prove that Webpack is part of the pipeline.

When troubleshooting, start by running ng build --stats-json. This flag creates a stats.json file that you can open with the Webpack Bundle Analyzer. The visual report shows entry points, module sizes, and chunk relationships, confirming that the bundle originated from Webpack.

If you suspect that a third‑party library is not being processed correctly, add the library name to the allowedCommonJsDependencies array in angular.json. This tells the Angular Webpack plugin to treat the library as a CommonJS module, preventing warnings and ensuring proper inclusion.

Finally, remember that the Angular CLI caches build artifacts in the node_modules/.cache folder. Deleting that cache forces a fresh Webpack compilation, which can resolve stale‑module issues.

In this article
  1. Default Build Tool
  2. CLI Invocation Details
  3. Customizing the Build
  4. Alternative Build Tools
  5. Verifying the Build Process