what is module federation

11 months ago 20
Nature

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications, or micro-frontends. It is a feature in Webpack 5 that manages a dependency graph for shared dependencies, enabling more independent and straightforward code sharing. With Module Federation, an application can run code dynamically from another bundle or build with its code-sharing and functionality-consuming abilities during runtime, paving the path to the successful utilization of micro-frontend technology.

Module Federation distinguishes between local and remote modules. Local modules are regular modules that are part of the current build, while remote modules are modules that are not part of the current build but are loaded at runtime from a remote container. It orchestrates the process of loading and dynamically configuring these remote modules, including dependency management. If a dependency is missing, the dependency will be automatically downloaded by the host application.

Module Federation improves operational efficiency by reusing the same code across multiple applications, allowing for the creation of truly modular applications that can be independently deployed and managed. It also supports lazy loading bundles to load modules only when necessary, resulting in better web performance.

In summary, Module Federation is a feature in Webpack 5 that enables sharing code and resources across multiple JavaScript applications, allowing for more independent and straightforward code sharing and improving operational efficiency.