Update:
For Angular 8+ read this AngularInDepth article.
For Angular 6 and 7:
The full article can be found here.
For the sake of simplicity I assume that the new builder is implemented in Typescript, but it can be implemented in pure JavaScript as well.
Implementation:
- Create a directory for your custom builders (for example custom-builders) in the root of your project (or alternatively install it as a local npm module)
- Inside the directory create a file called builders.json, index.ts and package.json that contains buildersentry pointing to builders.json
- Inside custom-builders create a directory for the builder you want to implement (say, custom-builders/my-cool-builder
- Add index.ts, schema.json and schema.d.ts to my-cool-builder directory
- Populate schema.json with the schema of your builder options. See an example here.
- Define your schema.d.ts according to the schema.json you defined. See an example here.
- Implement your builder in my-cool-builder/index.ts. The builder has to implement the following interface:   - export interface Builder<OptionsT> {
  run(builderConfig: BuilderConfiguration<Partial<OptionsT>>):  Observable<BuildEvent>;
}
 - While - BuildEventis this:
 - export interface BuildEvent {
  success: boolean;
}
 - BuilderConfigurationis this:
 - export interface BuilderConfiguration<OptionsT = {}> {
  root: Path;
  sourceRoot?: Path;
  projectType: string;
  builder: string;
  options: OptionsT;
}
 - And - OptionsTis the interface you defined for your builder options in schema.d.ts
 - You can use - browserarchitect target as a reference.
 
- Once implemented, add your builder to builders.json:   - {
  "$schema": "@angular-devkit/architect/src/builders-schema.json",
  "builders": {
    "cool-builder": {
      "class": "./my-cool-builder",
      "schema": "./my-cool-builder/schema.json",
      "description": "My cool builder that builds things up"
    }
  }
}
 
Usage:
In your angular.json:
    "architect": {
        ...
        "build": {
                  "builder": "./custom-builders:cool-builder"
                  "options": {
                         your options here
                  }
Example
For the full example check out this library: https://github.com/meltedspark/angular-builders