logologo
指南
实践
配置
插件
案例
博客
生态
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
指南
实践
配置
插件
案例
博客
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo
Overview
name
filename
remotes
exposes
shared
runtimePlugins
getPublicPath
implementation
dts
dev
manifest
shareStrategy
experiments
Edit this page on GitHub
Previous PageshareStrategy

#Experiments

experiments 配置用于启用插件中的实验功能。

  • Example
new ModuleFederationPlugin({
  name: '@demo/host',
  experiments: {
    asyncStartup: true,
    externalRuntime: false,
    provideExternalRuntime: false
  },
  shared: {
    react: {
      singleton: true,
    },
    'react-dom': {
      singleton: true,
    },
  },
  //...
});

#asyncStartup

  • Type: boolean
  • Required: No
  • Default: false

启用 asyncStartup 后,所有 Module Federation 入口将默认以异步方式初始化。这意味着:

  • 无需在应用顶部手动添加 import() 语句(例如 import('./bootstrap'))
  • 所有入口都会自动处理异步初始化
  • 通过自动的异步处理机制防止 "eager consumption" 错误
WARNING

使用此模式时,所有入口都将异步初始化。如果你手动 require 一个打包后的入口或导出 UMD 库,它将返回一个 promise 来解析导出内容。

#externalRuntime

  • Type: boolean
  • Required: No
  • Default: false

设置 true 后 会 external MF runtime,并使用消费者提供的 runtime 。(请确保你的消费者有设置 provideExternalRuntime: true,否则无法正常运行!)

#provideExternalRuntime

  • Type: boolean
  • Required: No
  • Default: false
注意

请确保仅在最顶层消费者配置!若同时有多个消费者注入 runtime,后执行的不会覆盖已有的 runtime。

设置 true 后会在消费者处注入 MF runtime。