Angular CLI 6 introduced a new concept of builders (aka Architect Targets).
There are a couple of prebuilt builders that come with @angular-devkit/build_angular
, but unfortunately there is no documentation that explains how to create your own builder.
How do I create my own builder (for example to modify the underlying webpack configuration)?
For those who use Angular 8 and higher, builders API is now officially supported and documented: https://angular.io/guide/cli-builder
It has a lot of changes compared to the previous version, so migration from Angular 7 to 8 might become complicated if you are using undocumented Architect API.
Here's a nice article to get started: https://blog.angular.io/introducing-cli-builders-d012d4489f1b
I didn't test it and I'm not quite sure, but this concept might be solution.
architect.build.builder
uses some Angular schematics in order to perform build process. You can create your own schematics which uses/inherits regular build schematics with additional logic that you want to implement.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:
builders
entry pointing to builders.jsonImplement your builder in my-cool-builder/index.ts. The builder has to implement the following interface:
While
BuildEvent
is this:BuilderConfiguration
is this:And
OptionsT
is the interface you defined for your builder options in schema.d.tsYou can use
browser
architect target as a reference.Once implemented, add your builder to builders.json:
Usage:
In your angular.json:
Example
For the full example check out this library: https://github.com/meltedspark/angular-builders