This executor is a drop-in replacement for the @angular-devkit/build-angular:browser builder provided by the Angular CLI. It builds an Angular application using webpack.

In addition to the features provided by the Angular CLI builder, the @nx/angular:webpack-browser executor also supports the following:

  • Providing a custom webpack configuration
  • Incremental builds
Dev Server

The @nx/angular:dev-server executor is required to serve your application when using the @nx/angular:webpack-browser to build it. It is a drop-in replacement for the Angular CLI's @angular-devkit/build-angular:dev-server builder and ensures the application is correctly served with Webpack when using the @nx/angular:webpack-browser executor.

Examples

The executor supports providing a path to a custom webpack configuration. This allows you to customize how your Angular application is built. It currently supports the following types of webpack configurations:

  • object
  • Function
  • Promise<object|Function>

The executor will merge the provided configuration with the webpack configuration that Angular Devkit uses. The merge order is:

  • Angular Devkit Configuration
  • Provided Configuration

To use a custom webpack configuration when building your Angular application, change the build target in your project.json to match the following:

project.json
1{ 2 ... 3 "targets": { 4 "build": { 5 "executor": "@nx/angular:webpack-browser", 6 "options": { 7 ... 8 "customWebpackConfig": { 9 "path": "apps/appName/webpack.config.js" 10 } 11 } 12 }, 13 ... 14 } 15} 16

Options

index

Required
oneOf [string, object ]

Configures the generation of the application's HTML index.

main

Required
string

The full path for the main entry point to the app, relative to the current workspace.

outputPath

Required
string

The full path for the new output directory, relative to the current workspace.

tsConfig

Required
string

The full path for the TypeScript configuration file, relative to the current workspace.

customWebpackConfig

Options for additional webpack configurations.

styles

Array<oneOf [object , string]>
Default: []

Global styles to be included in the build.

assets

Array<oneOf [object , string]>
Default: []

List of static application assets.

aot

boolean
Default: true

Build using Ahead of Time compilation.

allowedCommonJsDependencies

Array<string>
Default: []

A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use '*' to allow all.

baseHref

string

Base url for the application being built.

buildOptimizer

boolean
Default: true

Enables advanced build optimizations when using the 'aot' option.

budgets

Default: []

Budget thresholds to ensure parts of your application stay within boundaries which you set.

buildLibsFromSource

boolean
Default: true

Read buildable libraries from source instead of building them separately.

commonChunk

boolean
Default: true

Generate a separate bundle containing code used across multiple bundles.

crossOrigin

string
Default: none
Accepted values: none, anonymous, use-credentials

Define the crossorigin attribute setting of elements that provide CORS support.

deployUrl

string

Customize the base path for the URLs of resources in 'index.html' and component stylesheets. This option is only necessary for specific deployment scenarios, such as with Angular Elements or when utilizing different CDN locations.

deleteOutputPath

boolean
Default: true

Delete the output path before building.

extractLicenses

boolean
Default: true

Extract all licenses in a separate file.

fileReplacements

Array<oneOf [object , object ]>
Default: []

Replace compilation source files with other compilation source files in the build.

inlineStyleLanguage

string
Default: css
Accepted values: css, less, sass, scss

The stylesheet language to use for the application's inline component styles.

i18nMissingTranslation

string
Default: warning
Accepted values: warning, error, ignore

How to handle missing translations for i18n.

i18nDuplicateTranslation

string
Default: warning
Accepted values: warning, error, ignore

How to handle duplicate translations for i18n.

indexHtmlTransformer

indexFileTransformer
string

Path to transformer function to transform the index.html

localize

oneOf [boolean, Array<string>]

Translate the bundles in one or more locales.

namedChunks

boolean
Default: false

Use file name for lazy loaded chunks.

ngswConfigPath

string

Path to ngsw-config.json.

optimization

oneOf [object , boolean]
Default: true

Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.dev/reference/configs/workspace-config#optimization-configuration.

outputHashing

string
Default: none
Accepted values: none, all, media, bundles

Define the output filename cache-busting hashing mode.

polyfills

oneOf [Array<string>, string]

Polyfills to be included in the build.

progress

boolean
Default: true

Log progress to the console while building.

poll

number

Enable and define the file watching poll time period in milliseconds.

boolean

Do not use the real path when resolving modules. If unset then will default to true if NodeJS option --preserve-symlinks is set.

resourcesOutputPath

string
Default:

The path where style resources will be placed, relative to outputPath.

scripts

Array<oneOf [object , string]>
Default: []

Global scripts to be included in the build.

stylePreprocessorOptions

Options to pass to style preprocessors.

sourceMap

oneOf [object , boolean]
Default: false

Output source maps for scripts and styles. For more information, see https://angular.dev/reference/configs/workspace-config#source-map-configuration.

subresourceIntegrity

boolean
Default: false

Enables the use of subresource integrity validation.

serviceWorker

boolean
Default: false

Generates a service worker config for production builds.

statsJson

boolean
Default: false

Generates a 'stats.json' file which can be analyzed using tools such as 'webpack-bundle-analyzer'.

vendorChunk

boolean
Default: false

Generate a separate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time.

verbose

boolean
Default: false

Adds more details to output logging.

watch

boolean
Default: false

Run build when files change.

webWorkerTsConfig

string

TypeScript configuration for Web Worker modules.