Plugin System
Module Federation provides a lightweight runtime plugin system for implementing most of its features and allowing users to extend functionalities.
Plugins developed by developers can modify the default behavior of Module Federation and add various additional features, including but not limited to:
- Obtaining context information
- Registering lifecycle hooks
- Modifying Module Federation configurations
- ...
Developing Plugins
Plugins are provided in the form of a function similar to () => ModuleFederationRuntimePlugin.
Plugin Example
custom-runtime-plugin.ts
Registering plugins (either method is acceptable):
- Build-time registration of plugins
rspack.config.ts
- Runtime registration of plugins
Plugin Structure
Function-based plugins can accept an options object and return a plugin instance, managing internal state through closure mechanisms.
The roles of each part are as follows:
- The
nameproperty is used to label the plugin name. fnVarious hooks.
Naming Conventions
The naming conventions for plugins are as follows:
- The plugin function is named
xxx-pluginand is exported with a name. - The
nameof the plugin follows thexxx-pluginformat.
Here is an example:
Hooks
Refer to Runtime Hooks