So your Angular 6 project just went a bit beyond TODO app and you have to customize your build configuration.

The question is how?

Angular CLI 1.x ng eject VS Angular CLI 6 builders

In Angular CLI 1.x (Angular 5) you had ng eject command for this, which was ejecting the whole underlying webpack configuration and allowing you to modify it as you please.

In Angular CLI 6 this command has been temporarily disabled, and I suspect that it will be deprecated soon due to the new concept called Builders.

With the new Angular CLI you can customize the build process by defining your own builders as well as using one of the builders provided by the community.

Extending underlying webpack configuration

So lets go ahead and customize our build by extending the underlying webpack configuration:

Install @angular-builders/custom-webpack: npm i -D @angular-builders/custom-webpack .

Note that it requires version @angular-devkit/build-angular>=0.7.0 so you might need to install it (if not yet installed):

npm i -D @angular-devkit/build-angular

In angular.json change the @angular-devkit/build-angular:browser builder to @angular-builders/custom-webpack:browser :



" architect " : { ... " build " : { " builder " : " @angular-builders/custom-webpack:browser " " options " : { ... } ... }

If you build a universal app and would like to modify your server build configuration use @angular-builders/custom-webpack:server instead of @angular-builders/custom-webpack:browser

Add customWebpackConfig to the build target options :



" architect " : { ... " build " : { " builder " : " @angular-builders/custom-webpack:browser " " options " : { " customWebpackConfig " : { " path " : " ./extra-webpack.config.js " } ... } ... }

Check out the full description of customWebpackConfig object here.

Create extra-webpack.config.js in the root of your application (or whatever path you specified in angular.json).

Fill it with extra configuration you need (plain webpack configuration).

Note that in contrary to ng eject this configuration will be merged with the default Angular build configuration so you only have to configure the part you want to change/add. For example, if you want to add another webpack loader, your webpack config will look like this:

module . exports = { module : { rules : [ { test : / \. cool$/ , use : ' cool-loader ' } ] } };

And what about ng serve?

If you want to run ng serve with custom webpack configuration (given you performed all the above steps) you should do the following:

Install @angular-builders/dev-server

Replace @angular-devkit/build-angular:dev-server inside the serve target with @angular-builders/dev-server:generic

inside the serve target with Run ng serve

Additional sources

You can check out this electron-angular-native project for the example of Electron Angular application with node addons built with Angular CLI 6.

What is next

In the next article we will learn how to create your own builder.