ngx-build-plus

20.0.0 · active · verified Tue Apr 21

ngx-build-plus is an Angular CLI extension that allows developers to customize the webpack build process without needing to "eject" the Angular application. It enables integration of custom webpack configurations or functions, offering a flexible way to modify how Angular projects are built and served. The current stable version is 20.0.0, tightly coupled to Angular CLI 20.x, ensuring compatibility with the latest Angular ecosystem. It typically releases new major versions in alignment with Angular's major releases. Key differentiators include its non-ejecting approach, support for `ng serve` and `ng build` parity, schematics for common advanced use cases like webpack externals, and options for building single bundles, useful for Angular Elements. It provides a simple API for merging partial webpack configurations or using a custom hook function to modify the default CLI webpack config.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to add ngx-build-plus, create a partial webpack configuration (`webpack.partial.js`) to define a global `VERSION` constant, integrate it into an `app.component.ts`, and apply it to an Angular project via `ng serve --extra-webpack-config webpack.partial.js -o` after running `ng add ngx-build-plus`.

const webpack = require('webpack');

module.exports = {
    plugins: [
        new webpack.DefinePlugin({
            "VERSION": JSON.stringify("4711")
        })
    ]
};

// src/app/app.component.ts
import { Component } from '@angular/core';

declare const VERSION: string; // Declare global variable defined by webpack

@Component({
    selector: 'app-root',
    template: `<h1>{{ title }}</h1>`,
    styles: ['h1 { color: blue; }']
})
export class AppComponent {
    title = 'Version: ' + VERSION;
}

view raw JSON →