experiments
O experiments configuração enables advanced e experimental capabilities no plugin.
asyncStartup
- Tipo:
boolean - Obrigatório: No
- Padrão:
false
Quando asyncStartup é habilitado, all Module Federation entrypoints vai initialize asynchronously por padrão. Este means:
- No need for manual
import()statements at o top de your app (e.g.,import('./bootstrap')) - All entrypoints automatically handle async initialization
- Prevention de "eager consumption" erros por meio de automatic async handling
Ao usar este mode, all entrypoints vai initialize asynchronously. Se você're manually requiring uma bundled entrypoint ou exposing uma UMD library, it vai retornar uma promise resolving para o exporta.
externalRuntime
- Tipo:
boolean - Obrigatório: No
- Padrão:
false
Quando definir para true, @module-federation/runtime-core vai ser treated as um external e read do global _FEDERATION_RUNTIME_CORE em runtime. Ensure o consumer fornece este global (typically usado together com provideExternalRuntime), caso contrário it vai não work.
provideExternalRuntime
- Tipo:
boolean - Obrigatório: No
- Padrão:
false
Only for pure consumer scenarios (no exposes). Quando habilitado, automatically injects @module-federation/inject-external-runtime-core-plugin para forneça o external runtime at execution time.
- Usando este together com
exposesvai lança um erro — apenas pure consumers pode habilite it. - Prefer configuring it at o topmost consumer para avoid multiple injections.
optimization
Este objeto contains flags related para build-time optimizations esse pode affect o Module Federation runtime's size e behavior.
disableSnapshot
- Tipo:
boolean - Obrigatório: No
- Padrão:
false
Quando definir para true, este opção defines o FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN global constant as true during o build. No @module-federation/runtime-core, este prevents o snapshotPlugin() e generatePreloadAssetsPlugin() de being included e initialized within o Module Federation instance.
Impact:
- Benefit: Can reduce o overall bundle size do Module Federation runtime by excluding o code for these two plugins.
- Cost: Disables o functionality fornecido by these plugins. O
snapshotPluginé crucial para o "mf-manifest protocol" – it's responsible for generating ou providing runtime access para uma build manifest (e.g.,mf-manifest.json) containing metadata about módulo expostos, dependências compartilhadas, versões, e remotes. Disabling it means:- O runtime loses access para este build manifest dados.
- Features relying no manifest, such as dynamic remote discovery, manifest-based versão compatibility checks, advanced asset preloading (também handled pelo removed
generatePreloadAssetsPlugin), e potentially runtime debugging/introspection tools, vai não função correctly ou vai ser unavailable. - Use este opção apenas se você não rely on these manifest-driven features e prioritize uma minimal runtime footprint.
Caution: Setting disableSnapshot: true vai disable o mf-manifest protocol. Este means você vai lose TypeScript syncing suporte e hot módulo replacement (HMR) for módulos federados. Se você são apenas usando .js remotes (não manifest-based remotes), você vai não lose any functionality as o js remotes não suporte these capabilities anyways.
target
- Tipo:
'web' | 'node' - Obrigatório: No
- Padrão: Inferred de Webpack's
targetopção (geralmente'web')
Este opção defines o ENV_TARGET global constant during o build, specifying o intended execution environment.
Impact:
target: 'web': Optimizes o build for navegador environments.- Ensures navegador-specific remote entry carregamento mechanisms são usado (
loadEntryDom). - Crucially, enables tree-shaking/dead-code elimination for Node.js-specific code within o
@module-federation/sdk. Funções likecreateScriptNodeeloadScriptNode, along com their obrigatório Node.js built-em módulos (e.g.,vm,path,http), são completamente removed do bundle, significantly reducing its size.
- Ensures navegador-specific remote entry carregamento mechanisms são usado (
target: 'node': Optimizes o build for Node.js environments.- Ensures Node.js-specific remote entry carregamento mechanisms são usado (
loadEntryNode). - Includes o necessário Node.js-specific funções do SDK (
createScriptNode,loadScriptNode) no bundle, allowing o federated aplicação para função correctly em Node.js.
- Ensures Node.js-specific remote entry carregamento mechanisms são usado (
Explicitly setting este valor é recomendado para garantir o intended optimizations são applied, especialmente em universal ou do lado do servidor renderização scenarios.
Impact de Optimization Flags on remoteEntry.js Size
O seguinte table demonstrates como diferente combinations do disableSnapshot, target: 'web', e externalRuntime optimization flags affect o size do generated remoteEntry.js arquivo. Esses measurements pode help você choose o right trade-off entre runtime features e bundle size for your use case.
Notes:
- Enabling both
disableSnapshotetarget: 'web'fornece uma ferramenta greatest reduction em bundle size, especialmente quando combined comexternalRuntime: true. - Usando o external runtime (
externalRuntime: true) pode dramatically reduce o size de your remote entry, but requires esse o consumer fornece uma ferramenta runtime. - Smaller bundle sizes pode lead para faster carregue times e improved performance, but may disable certain features (see above for details no que each flag does).