This plugin implements Module Federation 1.5.
string
Provide a path as the implementation for Module Federation 1.5 runtime, which defaults to @module-federation/runtime-tools.
string[]
Provide the plugin required to run Module Federation 1.5, which can extend the behavior and capabilities of Module Federation.
string
Define the unique name exposed to other containers in the current build. This name will exist as a global variable for the remote container.
string
Specify the filename of the remote container entry file. Other containers will load the exposed modules through this file.
string | false
Define the runtime chunk for remote container entry.
LibraryOptions
Define the output format of remote container entry. The default libraryType is "var".
string
Define the namespace for shared dependencies in the current container. By configuring share scopes between different containers, the sharing behavior of modules can be controlled, including determining which modules are shared between different containers. The default share scope is "default"
.
'version-first' | 'loaded-first'
Control the loading strategy of shared dependencies:
'version-first'
: Version takes precedence. After setting, all remotes entry files will be automatically loaded and register the corresponding shared dependencies to ensure that all shared dependency versions can be obtained. This strategy is recommended when there are strict version requirements.
'loaded-first'
: reuse first. After setting, the remotes entry file will not be automatically loaded (it will only be loaded when needed), and registered shared dependencies will be reused first. This strategy is recommended when there are no strict requirements on the version and performance is required.
ExternalsType
Defines how to load remote containers, defaulting to "script"
, which loads via the <script />
tag.
Definition of the modules and their addresses that will be loaded remotely. The key is the name of the remote container, the value is the global variable name exposed by the remote container and the URL of the remote container entry. You can also specify shareScope to control whether the remote container shares dependencies.
Define how local modules can be referenced by remote containers. The key is the name of the module when referenced as a remote module in the remote container, and the value is the module path relative to the current folder. You can provide a name to specify the name of the exposed local module.
Specify which dependencies should be shared dependencies. This allows multiple micro-frontends to share the same instance of a dependency library to avoid loading the same code repeatedly. It can be an object dictionary where the keys are the names of the shared modules and the values are configuration or version strings. It can also be an array where the array items are the shared package names or configurations.
The SharedConfig can include the following sub-options:
true
, the shared module will be loaded in the initial chunk instead of being dynamically loaded when used. This means that the shared module will be loaded together with the main entry point regardless of whether it has been used. This can eliminate the delay caused by dynamic loading, but it will increase the size of the initial package. Also, please note that when this configuration is enabled, all provided modules and fallback modules will always be downloaded.package.json
. Configuration is only necessary when the package name cannot be automatically determined based on the request."^1.2.3"
. Used to set the version range of shared modules. If the module version of the remote container does not meet this range, the module will not be loaded."default"
.requiredVersion
. If set to true
, the shared module must match the version specified in requiredVersion exactly, otherwise an error will be reported and the module will not be loaded. If set to false
, it can tolerate imprecise matching.package.json
will be used.Found non-downgraded syntax in the build output?
If you need to be compatible with legacy browsers, please add builtin:swc-loader for syntax downgrade, and make sure it matches @module-federation/runtime
and @module-federation/sdk
. Here is an example: