//#region src/utils/ssrEntryLoader.d.ts /** * MF runtime plugin that intercepts the `loadEntry` lifecycle hook on the * server and loads the SSR-compatible remote entry instead of the browser one. * * This completely replaces the need for any `@module-federation/sdk` patches. * The `loadEntry` hook is emitted by `runtime-core` before it falls through to * `loadScriptNode` — if the hook returns a value, the runtime uses it directly. * * Strategy: * - In Node (detected through process.versions.node), fetch the remote's mf-manifest.json * to discover the ssrRemoteEntry URL and its type. * - ESM entry: use a dynamic `import()` — the SSR entry has no browser * globals and all shared packages are external. * - Dev mode (Vite 8+ only): use `ModuleRunner` with an HTTP transport backed * by the remote's `/__mf_runner__` endpoint. This fetches fully-transformed * module source through Vite's plugin pipeline, avoiding serialisation which * cannot faithfully represent React components or closures. * * Dev mode on Vite < 8 is NOT supported — `ModuleRunner` and * `FetchableDevEnvironment` are Vite 8+ APIs. If you need dev-mode SSR on * an older Vite version, implement an alternative loader in `loadSSRRemoteEntry` * for the `isDevSsrEntry` branch and expose a corresponding server endpoint * from `pluginSSRRemoteEntry.configureServer`. * * Exported as a plain factory function so it can be serialised into the * generated runtimePlugins list in virtualRemotes.ts. */ interface RemoteInfo { name: string; entry: string; type?: string; entryGlobalName?: string; } /** * MF runtime plugin factory. * * Usage in runtimePlugins: * import { ssrEntryLoaderPlugin } from '@module-federation/vite/ssrEntryLoader' * federation({ runtimePlugins: [ssrEntryLoaderPlugin] }) * * The plugin is also injected automatically for SSR contexts by the vite plugin. */ interface SsrEntryLoaderOptions { /** * Pre-resolved absolute file paths for common shared packages, keyed by * bare specifier. Populated at build time by the Vite plugin from the MF * plugin's own installed location so the resolution is package-manager- * agnostic. ssrEntryLoader uses these directly when rewriting bare specifiers * in remote SSR entry temp files — no runtime createRequire walk-up needed. */ resolvedShared?: Record; } declare function ssrEntryLoaderPlugin(options?: SsrEntryLoaderOptions): { name: string; loadEntry({ remoteInfo }: { remoteInfo: RemoteInfo; }): Promise<{ init: unknown; get: unknown; } | undefined>; }; //#endregion export { ssrEntryLoaderPlugin as default };