Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Angular CLI Builders: How to Create and Run a Custom Builder

Angular CLI builders are Architect-run task handlers. Learn how to package a custom builder, configure options and targets in angular.json, test it, and check built-in builders before migrating.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular CLI builders are task handlers that Angular’s Architect system runs for targets such as building, testing, or serving a project. To create a custom builder, package a handler with a JSON options schema and a builders.json manifest, then register it as a target in angular.json. Run that target with ng run project:target[:configuration].

How Angular CLI builders work

Angular’s CLI Builder API lets developers change CLI behavior by using builders to execute custom logic. A builder is the task-specific handler; Architect is the system that resolves and schedules the task.

As an Amazon Associate I earn from qualifying purchases.

The handler receives an options object and a BuilderContext. The context can provide runtime information and let the handler schedule other targets. A handler can return a result synchronously, return a Promise, or return an Observable when it needs to emit repeated results. The result is a BuilderOutput, which includes a success flag and may include an error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a custom builder package

A builder package needs an implementation, a schema describing accepted options, a manifest connecting the builder name to those files, and package metadata that points to the manifest. Angular’s guide demonstrates this structure and the createBuilder() API from @angular-devkit/architect.

  • src/my-builder.ts: implementation of the handler.
  • src/schema.json: JSON schema for the handler’s options.
  • builders.json: maps a builder name to the implementation and schema.
  • package.json: includes the builders field pointing to the manifest, along with package dependencies.

The guide’s example also includes TypeScript configuration and a test file. A package can be published to npm so a workspace can use it as a dependency.

In the guide’s illustrative identifier @example/copy-file:copy, @example/copy-file is the package name and copy is the builder name. The example handler uses createBuilder() and returns a Promise<BuilderOutput>.

Register and run the builder

A project’s angular.json file defines targets in its architect section. Each target names a builder in package-name:builder-name form and can specify default options and named configurations. Option names in the JSON file use camelCase; command-line flags use dash-case. See Angular’s workspace configuration reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, the builder guide shows a copy-package target configured to use @example/copy-file:copy, with source and destination defaults. The target can be run directly:

ng run builder-test:copy-package

A CLI argument can override a configured value; in the guide’s example, --destination=package-other.json replaces the target’s destination option. The general syntax is:

ng run project:target[:configuration]

Angular’s CLI reference documents the command. Use the project name and target as they appear in the workspace configuration; add a configuration name after the target when you want to select one.

How target options are resolved and validated

When Architect schedules a target, it combines inputs in this order:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Start with the target’s default options.
  2. Overlay the selected named configuration, if one was specified.
  3. Apply scheduling overrides, such as options passed on the CLI.

Architect checks the resolved options against the builder’s JSON schema before execution. This makes the schema part of the builder’s runtime contract: option names, types, and accepted values need to match what the handler expects.

There are two scheduling approaches with different resolution behavior. scheduleTarget() resolves a workspace target and its configuration. scheduleBuilder() receives an options object directly and validates it, but does not resolve target configuration. Choose based on whether the task should inherit a workspace target’s configured defaults.

Test and clean up builder execution

Angular recommends integration tests through Architect’s scheduler so tests exercise the builder in an Architect context. Unit tests are also useful for checking the task logic itself. If a builder returns an Observable, put cleanup in the Observable’s teardown logic so resources are released when execution ends or is unsubscribed. The builder guide covers the API and testing approach.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check built-in builders before changing a build target

Do not assume every project uses the same build builder. Angular’s current build guide lists these common build-target builders:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Builder Use Bundler or build behavior
@angular/build:application Application Builds an application bundle and server, and supports build-time prerendered routes using esbuild.
@angular-devkit/build-angular:browser-esbuild Browser bundle Uses esbuild.
@angular-devkit/build-angular:browser Browser bundle Uses webpack.
@angular/build:ng-packagr Angular Package Format library Builds a library.

The guide says generated applications use @angular/build:application by default, while generated libraries use @angular/build:ng-packagr. These defaults are not a substitute for inspecting your workspace: check the actual build target in angular.json. Builder names and defaults can vary with the Angular CLI release and project type.

Plan a builder change or migration

Before replacing a build builder, compare its output and project fit, its bundler, supported options, compatibility with the Angular version in use, and the builder’s migration documentation. An application builder and a library builder serve different outputs; a bundler change can also affect which options and workflows are supported.

There is no single migration recipe for every custom builder. Angular’s build-system migration guidance directs users of custom builders to the builder’s own documentation. Check that package’s compatibility notes and supported options against your current Angular version and target configuration before migrating.

If a target’s behavior depends on environment-specific values, review Angular’s build environments guide as well as the target’s named configurations. That helps distinguish environment configuration from builder behavior when diagnosing a build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.