Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 18, 2026·3 min de lecture

Module Federation — Share Code Between Independent Web Applications at Runtime

Module Federation is a Webpack 5 architecture pattern that allows multiple independently built JavaScript applications to share modules at runtime without bundling them together, enabling true micro-frontend architectures.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Module Federation
Commande d'installation directe
npx -y tokrepo@latest install 98d7ee42-8262-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Module Federation solves the problem of sharing code between separately deployed web applications. Instead of publishing packages to npm and rebuilding consumers, federated modules are loaded at runtime from their host URL. This enables teams to deploy independently while sharing components, utilities, and even state across applications.

What Module Federation Does

  • Enables runtime module sharing between independently deployed webpack builds
  • Allows any webpack build to expose and consume modules from other builds
  • Manages shared dependency versions to avoid duplicate React, lodash, or other libraries
  • Supports bidirectional sharing where any app can be both host and remote
  • Works with React, Vue, Angular, and vanilla JavaScript applications

Architecture Overview

Module Federation extends webpack's module system to load remote containers over HTTP at runtime. Each federated application produces a remoteEntry.js manifest listing its exposed modules and shared dependencies. When a host application imports a federated module, webpack's runtime fetches the remote container, negotiates shared dependency versions, and wires the module into the host's dependency graph transparently.

Self-Hosting & Configuration

  • Add ModuleFederationPlugin to each webpack 5 configuration
  • Define exposes to share modules and remotes to consume them
  • List shared dependencies to prevent duplicate bundles at runtime
  • Deploy each application independently to its own URL or CDN
  • Use @module-federation/enhanced for Rspack and Vite support

Key Features

  • Zero-rebuild sharing: update a remote module and all consumers get the new version instantly
  • Version negotiation for shared dependencies prevents duplicate library loads
  • Framework agnostic: works with React, Vue, Angular, Svelte, and vanilla JS
  • TypeScript support via @module-federation/typescript for type-safe remotes
  • Server-side rendering support for Node.js federated modules

Comparison with Similar Tools

  • npm packages — Require rebuilding and redeploying consumers; Module Federation updates at runtime
  • Micro frontends via iframes — Isolated but heavy; Module Federation shares a single React instance
  • single-spa — Framework for mounting micro frontends; Module Federation handles module loading
  • Import maps — Browser-native module resolution; Module Federation adds version negotiation and shared deps
  • Turborepo/Nx — Monorepo build tools; Module Federation enables independent deployment

FAQ

Q: Does it work with frameworks other than React? A: Yes. Module Federation is framework-agnostic and works with Vue, Angular, Svelte, and vanilla JavaScript.

Q: What happens if a remote module is unavailable? A: The import fails like any network request. Use React.lazy with error boundaries or dynamic import catch blocks to handle failures gracefully.

Q: Can I use it without webpack? A: The @module-federation/enhanced package supports Rspack and Vite. The core concept now extends beyond webpack.

Q: Does it increase bundle size? A: The runtime overhead is minimal (a few KB). Shared dependencies reduce total download size across micro frontends.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires