@module-federation/vite 1.23.2 → 1.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/lib/{dtsConstants-r5OfegUr.js → dtsConstants-DSTzyKSG.js} +11 -2
- package/lib/index.d.ts +1 -277
- package/lib/index.js +400 -175
- package/lib/normalizeModuleFederationOptions-DNUlv-AL.d.ts +303 -0
- package/lib/{pluginDts-DnEX3cp_.js → pluginDts-CVyHPAEq.js} +1 -1
- package/lib/{ssrEntryLoader-DEH3eV1e.js → ssrEntryLoader-DjZj-5Lw.js} +13 -7
- package/lib/{ssrVmStrategy-COMHOCN2.js → ssrVmStrategy-Dk5xXVvR.js} +1 -1
- package/lib/utils/ssrEntryLoader.d.ts +2 -59
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
2
|
+
import { ShareStrategy } from "@module-federation/runtime/types";
|
|
3
|
+
//#region src/utils/normalizeModuleFederationOptions.d.ts
|
|
4
|
+
interface RemoteObjectConfig {
|
|
5
|
+
type?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
internalName?: string;
|
|
8
|
+
entry: string;
|
|
9
|
+
entryGlobalName?: string;
|
|
10
|
+
shareScope?: string | string[];
|
|
11
|
+
}
|
|
12
|
+
interface TreeShakingConfig {
|
|
13
|
+
mode: 'server-calc' | 'runtime-infer';
|
|
14
|
+
usedExports?: string[];
|
|
15
|
+
}
|
|
16
|
+
interface PluginManifestOptions {
|
|
17
|
+
filePath?: string;
|
|
18
|
+
disableAssetsAnalyze?: boolean;
|
|
19
|
+
fileName?: string;
|
|
20
|
+
additionalData?: (options: {
|
|
21
|
+
stats: Record<string, unknown>;
|
|
22
|
+
manifest?: Record<string, unknown>;
|
|
23
|
+
pluginOptions: Record<string, unknown>;
|
|
24
|
+
compiler?: unknown;
|
|
25
|
+
compilation?: unknown;
|
|
26
|
+
bundler: 'vite';
|
|
27
|
+
}) => Promise<Record<string, unknown> | void> | Record<string, unknown> | void;
|
|
28
|
+
}
|
|
29
|
+
type ModuleFederationOptions = {
|
|
30
|
+
exposes?: Record<string, string | {
|
|
31
|
+
import: string;
|
|
32
|
+
}> | undefined;
|
|
33
|
+
filename?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Exact file name of the SSR remote entry emitted next to `filename`.
|
|
36
|
+
* Defaults to `<filename base>.ssr<ext>` so it never clobbers the browser
|
|
37
|
+
* entry when both builds share an output directory. `[hash]` is not supported.
|
|
38
|
+
*/
|
|
39
|
+
ssrFilename?: string;
|
|
40
|
+
library?: any;
|
|
41
|
+
name: string;
|
|
42
|
+
remotes?: Record<string, string | RemoteObjectConfig> | undefined;
|
|
43
|
+
runtime?: any;
|
|
44
|
+
shareScope?: string | string[];
|
|
45
|
+
/**
|
|
46
|
+
* Override the public path used for remote entries
|
|
47
|
+
* Defaults to Vite's base config or "auto" if base is empty
|
|
48
|
+
*/
|
|
49
|
+
publicPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Controls whether all CSS assets from the bundle should be added to every exposed module.
|
|
52
|
+
* When false (default), the plugin will not process any CSS assets.
|
|
53
|
+
* When true, all CSS assets are bundled into every exposed module.
|
|
54
|
+
*/
|
|
55
|
+
bundleAllCSS?: boolean;
|
|
56
|
+
/** Directory reserved for deploy-service generated secondary shared artifacts. */
|
|
57
|
+
treeShakingDir?: string;
|
|
58
|
+
/** Whether inferred usedExports metadata is injected into generated runtime records. */
|
|
59
|
+
injectTreeShakingUsedExports?: boolean;
|
|
60
|
+
treeShakingSharedPlugins?: string[];
|
|
61
|
+
treeShakingSharedExcludePlugins?: string[];
|
|
62
|
+
shared?: string[] | Record<string, string | {
|
|
63
|
+
name?: string;
|
|
64
|
+
version?: string;
|
|
65
|
+
shareScope?: string;
|
|
66
|
+
request?: moduleFederationPlugin.SharedConfig['request'];
|
|
67
|
+
shareKey?: moduleFederationPlugin.SharedConfig['shareKey'];
|
|
68
|
+
singleton?: boolean;
|
|
69
|
+
eager?: boolean;
|
|
70
|
+
requiredVersion?: moduleFederationPlugin.SharedConfig['requiredVersion'];
|
|
71
|
+
strictVersion?: boolean;
|
|
72
|
+
allowNodeModulesSuffixMatch?: boolean;
|
|
73
|
+
/** Suppress the missing local dependency warning for `import: false` shares. */
|
|
74
|
+
suppressMissingImportWarning?: boolean;
|
|
75
|
+
treeShaking?: TreeShakingConfig;
|
|
76
|
+
import?: moduleFederationPlugin.SharedConfig['import'];
|
|
77
|
+
}> | undefined;
|
|
78
|
+
runtimePlugins?: Array<string | [string, Record<string, unknown>]>;
|
|
79
|
+
getPublicPath?: string;
|
|
80
|
+
implementation?: string;
|
|
81
|
+
manifest?: PluginManifestOptions | boolean;
|
|
82
|
+
dev?: boolean | PluginDevOptions;
|
|
83
|
+
dts?: boolean | PluginDtsOptions;
|
|
84
|
+
shareStrategy?: ShareStrategy;
|
|
85
|
+
ignoreOrigin?: boolean;
|
|
86
|
+
virtualModuleDir?: string;
|
|
87
|
+
hostInitInjectLocation?: HostInitInjectLocationOptions;
|
|
88
|
+
/**
|
|
89
|
+
* Timeout for parsing modules in seconds.
|
|
90
|
+
* Defaults to 10 seconds.
|
|
91
|
+
*/
|
|
92
|
+
moduleParseTimeout?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Idle timeout for parsing modules in seconds. When set, the timeout resets
|
|
95
|
+
* on every parsed module and only fires when there has been no module activity
|
|
96
|
+
* for the configured duration. Prefer this over `moduleParseTimeout` for large
|
|
97
|
+
* codebases where the total build time may exceed the fixed timeout.
|
|
98
|
+
*/
|
|
99
|
+
moduleParseIdleTimeout?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Allows generate additional remoteEntry file for "var" host environment
|
|
102
|
+
*/
|
|
103
|
+
varFilename?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Target environment for the build to enable effective tree-shaking.
|
|
106
|
+
*
|
|
107
|
+
* @see https://module-federation.io/configure/experiments#target
|
|
108
|
+
* @default 'web' (or 'node' if build.ssr is enabled)
|
|
109
|
+
*/
|
|
110
|
+
target?: 'web' | 'node';
|
|
111
|
+
/**
|
|
112
|
+
* Removes remote-consumption support from the federation runtime.
|
|
113
|
+
* Only enable this for builds that never load remotes.
|
|
114
|
+
*
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
117
|
+
disableRemote?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Removes shared-dependency support from the federation runtime.
|
|
120
|
+
* Only enable this when the build has no shared dependencies.
|
|
121
|
+
*
|
|
122
|
+
* @default false
|
|
123
|
+
*/
|
|
124
|
+
disableShared?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Removes snapshot support, including manifest-based remotes, preload,
|
|
127
|
+
* dynamic type hints, HMR, and devtools integration.
|
|
128
|
+
*
|
|
129
|
+
* @default false (true for Node/SSR builds)
|
|
130
|
+
*/
|
|
131
|
+
disableSnapshot?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Additional packages to mark as external in the SSR remote entry build.
|
|
134
|
+
* Shared packages and MF runtime packages are external by default. Use this to
|
|
135
|
+
* add any other Node-only packages that should not be bundled into the SSR entry.
|
|
136
|
+
* To emit a self-contained SSR entry (loadable by hosts that cannot resolve the
|
|
137
|
+
* MF runtime from Node, such as the `@module-federation/sdk` reference loader),
|
|
138
|
+
* opt the MF runtime packages back in through Vite's `ssr.noExternal`.
|
|
139
|
+
*/
|
|
140
|
+
ssrExternals?: string[];
|
|
141
|
+
/**
|
|
142
|
+
* Options for the auto-injected `@module-federation/vite/ssrEntryLoader`.
|
|
143
|
+
* When omitted, the loader uses the `'temp-file'` strategy. Set
|
|
144
|
+
* `strategy: 'vm'` to opt into `vm.SourceTextModule` evaluation while keeping
|
|
145
|
+
* the computed `resolvedShared` map. Optional `maxAgeMs`, `fetchTimeoutMs`,
|
|
146
|
+
* and `fetchMaxBytes` are forwarded to the loader when set.
|
|
147
|
+
*/
|
|
148
|
+
ssrEntryLoader?: SsrEntryLoaderConfig;
|
|
149
|
+
/**
|
|
150
|
+
* Experimental Module Federation capabilities.
|
|
151
|
+
*
|
|
152
|
+
* @see https://module-federation.io/configure/experiments
|
|
153
|
+
*/
|
|
154
|
+
experiments?: PluginExperimentsOptions;
|
|
155
|
+
};
|
|
156
|
+
interface PluginExperimentsOptions {
|
|
157
|
+
/**
|
|
158
|
+
* Treat `@module-federation/runtime-core` as an external that reads
|
|
159
|
+
* `globalThis._FEDERATION_RUNTIME_CORE` at runtime. Pair with a host that
|
|
160
|
+
* sets `provideExternalRuntime: true`.
|
|
161
|
+
*/
|
|
162
|
+
externalRuntime?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Injects a local runtime plugin that publishes `runtime-core` on
|
|
165
|
+
* `globalThis._FEDERATION_RUNTIME_CORE`. Set it on exactly one container
|
|
166
|
+
* per page; that container may also `exposes`.
|
|
167
|
+
*/
|
|
168
|
+
provideExternalRuntime?: boolean;
|
|
169
|
+
/** Generate the React SSR/hydration island capability for eligible exposes. */
|
|
170
|
+
ssrMode?: 'ISLAND';
|
|
171
|
+
/**
|
|
172
|
+
* The host provides every shared dependency; remotes bring none. Shared keys
|
|
173
|
+
* are resolved by a native browser import map instead of the Module
|
|
174
|
+
* Federation runtime: the host emits one entry chunk per shared key and
|
|
175
|
+
* injects `<script type="importmap">`, remotes keep shared imports as bare
|
|
176
|
+
* specifiers and emit one fixed-name entry per expose plus a standard
|
|
177
|
+
* `mf-manifest.json` (without `remoteEntry`) the host maps from.
|
|
178
|
+
*
|
|
179
|
+
* Shared modules become ordinary static ES imports, so there is no
|
|
180
|
+
* `loadShare` glue and no `eager` is needed for code that reads a shared
|
|
181
|
+
* value at module-evaluation time. There is no version negotiation and no
|
|
182
|
+
* runtime API: `requiredVersion`, `strictVersion`, `shareStrategy`,
|
|
183
|
+
* `runtimePlugins` and `manifest` are ignored.
|
|
184
|
+
*
|
|
185
|
+
* @see https://github.com/module-federation/vite/issues/1381
|
|
186
|
+
*/
|
|
187
|
+
hostProvidesAllShared?: boolean;
|
|
188
|
+
}
|
|
189
|
+
type SsrEntryLoaderStrategy = 'temp-file' | 'vm';
|
|
190
|
+
type SsrEntryLoaderConfig = {
|
|
191
|
+
/**
|
|
192
|
+
* How the auto-injected `@module-federation/vite/ssrEntryLoader` evaluates
|
|
193
|
+
* remote SSR entries.
|
|
194
|
+
*
|
|
195
|
+
* - `'temp-file'` (default when omitted): fetch the ESM graph, rewrite
|
|
196
|
+
* specifiers, write temp files and `import()` them. Works on stock Node;
|
|
197
|
+
* shared packages are pinned to the host's copies via `resolvedShared`
|
|
198
|
+
* (no version negotiation).
|
|
199
|
+
* - `'vm'`: evaluate the graph with `vm.SourceTextModule` and link bare
|
|
200
|
+
* shared imports through the host's federation share scope (`loadShare`),
|
|
201
|
+
* restoring version negotiation. Requires `--experimental-vm-modules`; the
|
|
202
|
+
* loader emits a single warning and falls back to `'temp-file'` when that
|
|
203
|
+
* API is unavailable.
|
|
204
|
+
*/
|
|
205
|
+
strategy?: SsrEntryLoaderStrategy;
|
|
206
|
+
/**
|
|
207
|
+
* Re-check each remote's manifest when the cached SSR entry resolution is
|
|
208
|
+
* older than this many milliseconds. When the manifest's version changes
|
|
209
|
+
* (remote redeployed at the same URL), the loader drops its caches for that
|
|
210
|
+
* remote so subsequent loads use the new build. Omit to cache until process
|
|
211
|
+
* exit or an explicit `revalidate()` call. Only manifest-resolved entries
|
|
212
|
+
* can be revalidated this way — convention-resolved entries have no version
|
|
213
|
+
* source.
|
|
214
|
+
*/
|
|
215
|
+
maxAgeMs?: number;
|
|
216
|
+
/**
|
|
217
|
+
* Maximum time in milliseconds for each SSR network request. Defaults to
|
|
218
|
+
* 10 seconds. Set to `0` to disable the timeout.
|
|
219
|
+
*/
|
|
220
|
+
fetchTimeoutMs?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Maximum response body size in bytes for each SSR network request. Defaults
|
|
223
|
+
* to 10 MiB. Set to `0` to disable the limit.
|
|
224
|
+
*/
|
|
225
|
+
fetchMaxBytes?: number;
|
|
226
|
+
};
|
|
227
|
+
type HostInitInjectLocationOptions = 'entry' | 'html';
|
|
228
|
+
interface PluginDevOptions {
|
|
229
|
+
disableLiveReload?: boolean;
|
|
230
|
+
disableHotTypesReload?: boolean;
|
|
231
|
+
disableDynamicRemoteTypeHints?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Controls cross-federation HMR for remote modules.
|
|
234
|
+
*
|
|
235
|
+
* - `false` / `undefined` — HMR disabled (default).
|
|
236
|
+
* - `true` — HMR enabled with auto-detected strategy. When a framework
|
|
237
|
+
* plugin with cross-federation HMR support is detected, broadcast/relay
|
|
238
|
+
* is suppressed and the framework's native HMR handles updates:
|
|
239
|
+
* - React (`@vitejs/plugin-react` / `@vitejs/plugin-react-swc`) — the
|
|
240
|
+
* plugin serves a `/@react-refresh` proxy on remotes that delegates
|
|
241
|
+
* to the host's `RefreshRuntime`, unifying the component registry.
|
|
242
|
+
* - Vue (`@vitejs/plugin-vue` / `@vitejs/plugin-vue-jsx`) — the plugin
|
|
243
|
+
* injects a `__VUE_HMR_RUNTIME__` guard into the host page so the
|
|
244
|
+
* first-loaded (host) Vue runtime is pinned and remote-loaded Vue
|
|
245
|
+
* copies cannot overwrite it.
|
|
246
|
+
* For any host, the plugin also injects a script that clears the
|
|
247
|
+
* federation `moduleCache` on `vite:beforeUpdate` so subsequent
|
|
248
|
+
* `loadRemote()` calls return the freshly patched module.
|
|
249
|
+
* Other frameworks fall back to full page reloads.
|
|
250
|
+
* - `'full-reload'` — HMR enabled, always use full page reloads even when
|
|
251
|
+
* a framework with native cross-federation HMR is detected.
|
|
252
|
+
*/
|
|
253
|
+
remoteHmr?: boolean | 'full-reload';
|
|
254
|
+
}
|
|
255
|
+
interface RemoteTypeUrl {
|
|
256
|
+
alias?: string;
|
|
257
|
+
api: string;
|
|
258
|
+
zip: string;
|
|
259
|
+
}
|
|
260
|
+
interface RemoteTypeUrls {
|
|
261
|
+
[remoteName: string]: RemoteTypeUrl;
|
|
262
|
+
}
|
|
263
|
+
interface PluginDtsOptions {
|
|
264
|
+
generateTypes?: boolean | DtsRemoteOptions;
|
|
265
|
+
consumeTypes?: boolean | DtsHostOptions;
|
|
266
|
+
tsConfigPath?: string;
|
|
267
|
+
extraOptions?: Record<string, unknown>;
|
|
268
|
+
implementation?: string;
|
|
269
|
+
cwd?: string;
|
|
270
|
+
displayErrorInTerminal?: boolean;
|
|
271
|
+
}
|
|
272
|
+
interface DtsRemoteOptions {
|
|
273
|
+
tsConfigPath?: string;
|
|
274
|
+
typesFolder?: string;
|
|
275
|
+
compiledTypesFolder?: string;
|
|
276
|
+
deleteTypesFolder?: boolean;
|
|
277
|
+
additionalFilesToCompile?: string[];
|
|
278
|
+
compilerInstance?: 'tsc' | 'vue-tsc' | 'tspc' | string;
|
|
279
|
+
compileInChildProcess?: boolean;
|
|
280
|
+
generateAPITypes?: boolean;
|
|
281
|
+
extractThirdParty?: boolean | {
|
|
282
|
+
exclude?: Array<string | RegExp>;
|
|
283
|
+
};
|
|
284
|
+
extractRemoteTypes?: boolean;
|
|
285
|
+
abortOnError?: boolean;
|
|
286
|
+
deleteTsConfig?: boolean;
|
|
287
|
+
afterGenerate?: (options: moduleFederationPlugin.DtsGenerateTypesHookOptions) => Promise<void> | void;
|
|
288
|
+
}
|
|
289
|
+
interface DtsHostOptions {
|
|
290
|
+
typesFolder?: string;
|
|
291
|
+
abortOnError?: boolean;
|
|
292
|
+
remoteTypesFolder?: string;
|
|
293
|
+
deleteTypesFolder?: boolean;
|
|
294
|
+
maxRetries?: number;
|
|
295
|
+
consumeAPITypes?: boolean;
|
|
296
|
+
runtimePkgs?: string[];
|
|
297
|
+
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
|
|
298
|
+
timeout?: number;
|
|
299
|
+
family?: 0 | 4 | 6;
|
|
300
|
+
typesOnBuild?: boolean;
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
export { SsrEntryLoaderStrategy as a, SsrEntryLoaderConfig as i, PluginExperimentsOptions as n, TreeShakingConfig as o, PluginManifestOptions as r, ModuleFederationOptions as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as normalizePathForImport, n as mfError, t as createModuleFederationError } from "./logger-DOwfTlw5.js";
|
|
2
|
-
import { g as resolveImportPath, u as hasPackageDependency } from "./dtsConstants-
|
|
2
|
+
import { g as resolveImportPath, u as hasPackageDependency } from "./dtsConstants-DSTzyKSG.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import { normalizeOptions } from "@module-federation/sdk";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as CodeRewriter, i as createCodePositionMap, r as mfWarn, s as EXTERNAL_URL_RE } from "./logger-DOwfTlw5.js";
|
|
2
|
+
import { simpleJoinRemoteEntry } from "@module-federation/sdk";
|
|
2
3
|
//#region src/utils/fetchWithTimeout.ts
|
|
3
4
|
const DEFAULT_SSR_FETCH_TIMEOUT_MS = 1e4;
|
|
4
5
|
const DEFAULT_SSR_FETCH_MAX_BYTES = 10 * 1024 * 1024;
|
|
@@ -361,15 +362,14 @@ function getEntryFilename(entryUrl) {
|
|
|
361
362
|
}
|
|
362
363
|
function resolveEntryAssetUrl(entry, manifestUrl) {
|
|
363
364
|
const base = manifestUrl.replace(/\/[^/]+$/, "/");
|
|
364
|
-
return new URL(
|
|
365
|
+
return new URL(simpleJoinRemoteEntry(entry.path || "", entry.name), base).href;
|
|
365
366
|
}
|
|
366
367
|
function resolveSSREntryUrl(manifest, manifestUrl) {
|
|
367
368
|
const entry = parseManifestEntry(manifest.metaData?.ssrRemoteEntry);
|
|
368
369
|
if (!entry) return null;
|
|
369
370
|
const base = manifestUrl.replace(/\/[^/]+$/, "/");
|
|
370
|
-
const entryPath = entry.path + entry.name;
|
|
371
371
|
return {
|
|
372
|
-
url: new URL(
|
|
372
|
+
url: new URL(simpleJoinRemoteEntry(entry.path, entry.name), base).href,
|
|
373
373
|
type: entry.type,
|
|
374
374
|
versionKey: computeManifestVersionKey(manifest)
|
|
375
375
|
};
|
|
@@ -834,7 +834,7 @@ async function importTempModule(filePath, versionKey) {
|
|
|
834
834
|
let warnedVmUnavailable = false;
|
|
835
835
|
let vmStrategyModulePromise;
|
|
836
836
|
function getVmStrategyModule() {
|
|
837
|
-
if (!vmStrategyModulePromise) vmStrategyModulePromise = import("./ssrVmStrategy-
|
|
837
|
+
if (!vmStrategyModulePromise) vmStrategyModulePromise = import("./ssrVmStrategy-Dk5xXVvR.js");
|
|
838
838
|
return vmStrategyModulePromise;
|
|
839
839
|
}
|
|
840
840
|
/**
|
|
@@ -902,9 +902,12 @@ async function loadSSRRemoteEntry(ssrEntry, options, rootEntryUrl) {
|
|
|
902
902
|
const cacheDir = await getSSRCacheDir();
|
|
903
903
|
mkdirSync(cacheDir, { recursive: true });
|
|
904
904
|
const sharedPkgMap = new Map(Object.entries(resolvedShared));
|
|
905
|
-
const
|
|
905
|
+
const isCommonJs = type === "commonjs-module" || type === "commonjs";
|
|
906
|
+
const extension = isCommonJs ? ".cjs" : ".mjs";
|
|
906
907
|
try {
|
|
907
|
-
|
|
908
|
+
const tmpFile = await fetchEsmGraphToTempFile(url, cacheDir, sharedPkgMap, versionKey, options.fetchTimeoutMs, getSsrTransformContextKey(resolvedShared, options.shareScopeName), options.fetchMaxBytes, extension, rootEntryUrl);
|
|
909
|
+
if (isCommonJs) return (await _module()).createRequire(import.meta.url)(tmpFile);
|
|
910
|
+
return await importTempModule(tmpFile, versionKey);
|
|
908
911
|
} catch (error) {
|
|
909
912
|
if (isSsrEntryHttpError(error) || isSsrFetchBodyTooLargeError(error)) throw error;
|
|
910
913
|
warnStrategyFallback("temp-file", url, "the federation runtime's loader", error);
|
|
@@ -941,7 +944,10 @@ function ssrEntryLoaderPlugin(options = {}) {
|
|
|
941
944
|
} : resolved;
|
|
942
945
|
const ssrEntry = await getSSREntry(remoteInfo.entry, loadOptions.maxAgeMs, loadOptions.fetchTimeoutMs, loadOptions.fetchMaxBytes);
|
|
943
946
|
if (!ssrEntry) return;
|
|
944
|
-
const mod = await loadSSRRemoteEntry(ssrEntry
|
|
947
|
+
const mod = await loadSSRRemoteEntry(ssrEntry.url === remoteInfo.entry && remoteInfo.type ? {
|
|
948
|
+
...ssrEntry,
|
|
949
|
+
type: remoteInfo.type
|
|
950
|
+
} : ssrEntry, loadOptions, remoteInfo.entry);
|
|
945
951
|
if (!mod) return;
|
|
946
952
|
return mod;
|
|
947
953
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as findSharedKey } from "./sharedKeyMatcher-Od_nYxJA.js";
|
|
2
|
-
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-
|
|
2
|
+
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-DjZj-5Lw.js";
|
|
3
3
|
//#region src/utils/ssrVmStrategy.ts
|
|
4
4
|
/**
|
|
5
5
|
* vm.SourceTextModule strategy for loading remote SSR entries.
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
+
import { i as SsrEntryLoaderConfig } from "../normalizeModuleFederationOptions-DNUlv-AL.js";
|
|
1
2
|
//#region src/utils/ssrEntryLoader.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* MF runtime plugin that intercepts the `loadEntry` lifecycle hook on the
|
|
4
|
-
* server and loads the SSR-compatible remote entry instead of the browser one.
|
|
5
|
-
*
|
|
6
|
-
* This completely replaces the need for any `@module-federation/sdk` patches.
|
|
7
|
-
* The `loadEntry` hook is emitted by `runtime-core` before it falls through to
|
|
8
|
-
* `loadScriptNode` — if the hook returns a value, the runtime uses it directly.
|
|
9
|
-
*
|
|
10
|
-
* Strategy:
|
|
11
|
-
* - In Node (detected through process.versions.node), fetch the remote's mf-manifest.json
|
|
12
|
-
* to discover the ssrRemoteEntry URL and its type.
|
|
13
|
-
* - ESM entry: use a dynamic `import()` — the SSR entry has no browser
|
|
14
|
-
* globals and all shared packages are external.
|
|
15
|
-
* - Dev mode (Vite 8+ only): use `ModuleRunner` with an HTTP transport backed
|
|
16
|
-
* by the remote's `/__mf_runner__` endpoint. This fetches fully-transformed
|
|
17
|
-
* module source through Vite's plugin pipeline, avoiding serialisation which
|
|
18
|
-
* cannot faithfully represent React components or closures.
|
|
19
|
-
*
|
|
20
|
-
* Dev mode on Vite < 8 is NOT supported by this integration because the
|
|
21
|
-
* cross-process `fetchModule` proxy uses Vite 8's environment APIs.
|
|
22
|
-
* `ModuleRunner` itself is available in earlier Vite versions, but an older
|
|
23
|
-
* remote needs a different transport and server endpoint.
|
|
24
|
-
*
|
|
25
|
-
* Exported as a plain factory function so it can be serialised into the
|
|
26
|
-
* generated runtimePlugins list in virtualRemotes.ts.
|
|
27
|
-
*/
|
|
28
3
|
interface RemoteInfo {
|
|
29
4
|
name: string;
|
|
30
5
|
entry: string;
|
|
@@ -63,7 +38,7 @@ declare function neutralizeBrowserPreloadHelpers(code: string): string;
|
|
|
63
38
|
*
|
|
64
39
|
* The plugin is also injected automatically for SSR contexts by the vite plugin.
|
|
65
40
|
*/
|
|
66
|
-
interface SsrEntryLoaderOptions {
|
|
41
|
+
interface SsrEntryLoaderOptions extends SsrEntryLoaderConfig {
|
|
67
42
|
/**
|
|
68
43
|
* Pre-resolved absolute file paths for common shared packages, keyed by
|
|
69
44
|
* bare specifier. Populated at build time by the Vite plugin from the MF
|
|
@@ -72,43 +47,11 @@ interface SsrEntryLoaderOptions {
|
|
|
72
47
|
* in remote SSR entry temp files — no runtime createRequire walk-up needed.
|
|
73
48
|
*/
|
|
74
49
|
resolvedShared?: Record<string, string>;
|
|
75
|
-
/**
|
|
76
|
-
* How to evaluate remote SSR entries on the server.
|
|
77
|
-
*
|
|
78
|
-
* - `'temp-file'` (default): fetch the ESM graph, rewrite specifiers, write
|
|
79
|
-
* temp files and `import()` them. Works on stock Node; shared packages are
|
|
80
|
-
* pinned to the host's copies via `resolvedShared` (no version negotiation).
|
|
81
|
-
* - `'vm'`: evaluate the graph with `vm.SourceTextModule` and link bare
|
|
82
|
-
* shared imports through the host's federation share scope (`loadShare`),
|
|
83
|
-
* restoring version negotiation. Requires `--experimental-vm-modules`;
|
|
84
|
-
* falls back to `'temp-file'` when unavailable.
|
|
85
|
-
*/
|
|
86
|
-
strategy?: 'temp-file' | 'vm';
|
|
87
50
|
/**
|
|
88
51
|
* Share scope consulted by the `'vm'` strategy when linking bare imports.
|
|
89
52
|
* Defaults to `'default'`.
|
|
90
53
|
*/
|
|
91
54
|
shareScopeName?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Re-check each remote's manifest when the cached SSR entry resolution is
|
|
94
|
-
* older than this many milliseconds. When the manifest's version changes
|
|
95
|
-
* (remote redeployed at the same URL), the loader drops its caches for that
|
|
96
|
-
* remote so subsequent loads use the new build. Omit to cache until process
|
|
97
|
-
* exit or an explicit `revalidate()` call. Only manifest-resolved entries
|
|
98
|
-
* can be revalidated this way — convention-resolved entries have no version
|
|
99
|
-
* source.
|
|
100
|
-
*/
|
|
101
|
-
maxAgeMs?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Maximum time in milliseconds for each SSR network request. Defaults to
|
|
104
|
-
* 10 seconds. Set to `0` to disable the timeout.
|
|
105
|
-
*/
|
|
106
|
-
fetchTimeoutMs?: number;
|
|
107
|
-
/**
|
|
108
|
-
* Maximum response body size in bytes for each SSR network request. Defaults
|
|
109
|
-
* to 10 MiB. Set to `0` to disable the limit.
|
|
110
|
-
*/
|
|
111
|
-
fetchMaxBytes?: number;
|
|
112
55
|
}
|
|
113
56
|
declare function ssrEntryLoaderPlugin(options?: SsrEntryLoaderOptions): {
|
|
114
57
|
name: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-
|
|
1
|
+
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-DjZj-5Lw.js";
|
|
2
2
|
export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|