Skip to main content
The @nx/webpack plugin integrates Webpack into your Nx workspace. It provides the webpack build executor, the dev-server executor for development serving, and the withNx() config helper that wires Nx features (like TypeScript path aliases and distributed caching) into your Webpack configuration.

Installation

Or install manually:

What the plugin provides

Executors

Build with webpack, serve with webpack-dev-server, and serve SSR applications.

Generators

Convert existing Webpack config files to use the NxAppWebpackPlugin pattern. Migrate executor-based configs to inferred tasks.

Inferred tasks

Detects webpack.config.js/ts files and infers build and serve targets automatically.

Generators

convert-config-to-webpack-plugin

Convert an existing Webpack configuration file to use the NxAppWebpackPlugin and NxReactWebpackPlugin pattern. This is the recommended approach for new projects.

convert-to-inferred

Migrate existing projects that use the @nx/webpack:webpack executor to use the inferred task plugin (@nx/webpack/plugin).

Executors

webpack

Build a web application using Webpack.

dev-server

Serve a web application in development mode using webpack-dev-server with hot module replacement.

ssr-dev-server

Serve a server-side rendered (SSR) application using two Webpack processes: one for the browser bundle and one for the server bundle.

Inferred tasks

When @nx/webpack/plugin is registered in nx.json, Nx detects webpack.config.js or webpack.config.ts files and automatically infers build and serve targets.

Configuration examples

webpack.config.js with NxAppWebpackPlugin

The recommended approach uses NxAppWebpackPlugin instead of manually calling withNx():

Legacy webpack.config.js with withNx

For projects that have not yet migrated to NxAppWebpackPlugin:
The withNx() helper automatically configures TypeScript path aliases, source maps, and other Nx-specific Webpack features. Use composePlugins to layer additional configuration on top.

Built-in loader support

@nx/webpack ships with loaders and plugins pre-configured for common use cases:

Styles

CSS, SCSS/Sass, Less — with css-loader, sass-loader, less-loader, and mini-css-extract-plugin.

TypeScript

TypeScript compilation via ts-loader or Babel with fork-ts-checker-webpack-plugin for type checking.

Assets

Static asset handling with copy-webpack-plugin.

Optimization

Production minification with terser-webpack-plugin and CSS minification with css-minimizer-webpack-plugin.