Module Federation lets you split a single-page application into independently built and deployable chunks. At runtime, a host application fetches remote modules over the network and executes them as if they were part of its own bundle. Nx provides generators, executors, and build-system utilities that make Module Federation approachable in a monorepo:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
Generators
Scaffold host and remote applications with a single command.
Smart serving
nx serve on the host automatically builds and serves all remotes.Type safety
Shared
ModuleFederationConfig type catches name mismatches early.Remote caching
Nx Cloud caches unchanged remote builds, so only changed remotes rebuild.
Prerequisites
Install the plugin for your framework:- React
- Angular
@nx/module-federation package is installed automatically as a dependency.
Generating a host with remotes
Generate a host application and wire up remotes in a single command:- React
- Angular
- A
hostapplication (apps/shell) with amodule-federation.config.tsreferencing each remote - One
remoteapplication per name listed in--remotes - Build and serve configuration for every application
Generating a remote separately
You can add remotes at any time and attach them to an existing host:- React
- Angular
--host flag causes the generator to update apps/shell/module-federation.config.ts automatically.
Module Federation config
Every host and remote has amodule-federation.config.ts file that declares the application’s name and, for hosts, the list of remotes:
name values must match exactly across host and remote configs — Nx validates this at build time.
Excluding or overriding shared libraries
All npm and workspace libraries are shared singletons by default. To exclude a library from sharing (for example, to enable tree shaking):Static vs dynamic federation
- Static federation
- Dynamic federation
Remote URLs are known at build time. The host’s Module Federation config lists remote names and Nx resolves their development ports automatically. For production, explicit URLs are set in a production-specific config:Static federation is the simpler approach and suits teams that deploy all applications together on the same release cadence.
Developing locally with nx serve
Serve the entire application (host + all remotes) with a single command:
shell depends on and:
- Builds each remote (or restores from cache if unchanged)
- Serves all remotes statically via a single
http-serverprocess - Serves the host via
webpack-dev-serveror the Rspack dev server with HMR
Developing a specific remote with HMR
To enable hot module replacement on one or more remotes while working on them:- React (Continuous Tasks)
- Angular
With Rspack and the
@nx/rspack/plugin inference plugin, simply serve the remote directly — the host starts automatically:Build configuration with Rspack (React)
For React, Nx uses Rspack by default. The generatedrspack.config.ts for a host looks like this:
Production build
Build the host and all its remotes:implicitDependencies to the host’s project.json:
dist/apps/ with one directory per application:
remoteEntry.js is the entry point the host fetches at runtime.
Remote caching with Nx Cloud
Module Federation splits the build into multiple independent processes. Without caching, building each remote separately is slower than a single monolithic build. Nx Cloud makes Module Federation fast by caching each remote’s build output.When a developer runs
nx serve shell, unchanged remotes are restored from cache rather than rebuilt. In a workspace with 100 remotes, only the remotes that changed since the last run are rebuilt.Supported bundler versions
| Bundler | Supported versions |
|---|---|
| webpack | ^5.0.0 |
| @rspack/core | ^1.6.0 |
