@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 CHANGED
@@ -278,6 +278,21 @@ federation({
278
278
 
279
279
  The `"vm"` strategy requires Node.js to run with `--experimental-vm-modules`. When unavailable, the loader warns once and falls back to `"temp-file"`. Vite 8 development uses `ModuleRunner`; this option primarily affects build and preview SSR entry loading.
280
280
 
281
+ `ssrEntryLoader` also accepts network and cache options:
282
+
283
+ ```ts
284
+ federation({
285
+ // ...
286
+ ssrEntryLoader: {
287
+ maxAgeMs: 60_000, // re-check each remote's manifest after 60s; omit to cache until process exit
288
+ fetchTimeoutMs: 5_000, // per-request timeout, default 10s, 0 disables it
289
+ fetchMaxBytes: 5 * 1024 * 1024, // per-response size limit, default 10 MiB, 0 disables it
290
+ },
291
+ });
292
+ ```
293
+
294
+ With `maxAgeMs`, a remote redeployed at the same URL is picked up once its manifest version changes. Only manifest-resolved entries can be revalidated.
295
+
281
296
  The SSR remote entry is emitted as `<filename base>.ssr.js` next to the browser entry, or under the exact name given by `ssrFilename`, and is advertised as `metaData.ssrRemoteEntry` in `mf-manifest.json`. It keeps `@module-federation/runtime`, `@module-federation/runtime-core` and `@module-federation/sdk` external by default so Node resolves them from the host. Hosts that cannot resolve those packages, such as a plain `@module-federation/enhanced` host using the SDK's reference Node loader, need a self-contained entry: opt the packages back in with Vite's `ssr.noExternal` (for example `ssr: { noExternal: true }`) on the remote.
282
297
 
283
298
  ## Runtime capability optimization
@@ -36,6 +36,7 @@ function getDependencyCacheKey(cwd, dependencyName) {
36
36
  }
37
37
  const installedPackageJsonCache = /* @__PURE__ */ new Map();
38
38
  const dependentsLookupCache = /* @__PURE__ */ new Map();
39
+ const reachableDependencyNames = /* @__PURE__ */ new Map();
39
40
  function setPackageDetectionCwd(cwd) {
40
41
  packageDetectionCwd = cwd;
41
42
  }
@@ -471,10 +472,17 @@ function resolveInstalledPackageJson(pkg, cwd, packageName, opts) {
471
472
  */
472
473
  function findPackageInDependents(packageName, cwd) {
473
474
  const cacheKey = `${cwd}\0${packageName}`;
474
- if (!dependentsLookupCache.has(cacheKey)) dependentsLookupCache.set(cacheKey, walkDependents(packageName, cwd));
475
+ if (!dependentsLookupCache.has(cacheKey)) {
476
+ if (!reachableDependencyNames.has(cwd)) {
477
+ const names = /* @__PURE__ */ new Set();
478
+ walkDependents("", cwd, names);
479
+ reachableDependencyNames.set(cwd, names);
480
+ }
481
+ dependentsLookupCache.set(cacheKey, reachableDependencyNames.get(cwd).has(packageName) ? walkDependents(packageName, cwd) : void 0);
482
+ }
475
483
  return dependentsLookupCache.get(cacheKey);
476
484
  }
477
- function walkDependents(packageName, cwd) {
485
+ function walkDependents(packageName, cwd, reachedNames) {
478
486
  const root = tryReadPackageJson(path$1.join(cwd, "package.json"));
479
487
  if (!root) return void 0;
480
488
  const visited = /* @__PURE__ */ new Set();
@@ -492,6 +500,7 @@ function walkDependents(packageName, cwd) {
492
500
  const dependent = findPackageFrom(name, fromDir);
493
501
  if (!dependent || visited.has(dependent.dir)) continue;
494
502
  visited.add(dependent.dir);
503
+ reachedNames?.add(name);
495
504
  const dependencies = getDependencyNames(dependent.packageJson);
496
505
  if (dependencies.includes(packageName)) {
497
506
  const copy = findPackageFrom(packageName, dependent.dir);
package/lib/index.d.ts CHANGED
@@ -1,280 +1,4 @@
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.
146
- */
147
- ssrEntryLoader?: SsrEntryLoaderConfig;
148
- /**
149
- * Experimental Module Federation capabilities.
150
- *
151
- * @see https://module-federation.io/configure/experiments
152
- */
153
- experiments?: PluginExperimentsOptions;
154
- };
155
- interface PluginExperimentsOptions {
156
- /**
157
- * Treat `@module-federation/runtime-core` as an external that reads
158
- * `globalThis._FEDERATION_RUNTIME_CORE` at runtime. Pair with a host that
159
- * sets `provideExternalRuntime: true`.
160
- */
161
- externalRuntime?: boolean;
162
- /**
163
- * Injects a local runtime plugin that publishes `runtime-core` on
164
- * `globalThis._FEDERATION_RUNTIME_CORE`. Set it on exactly one container
165
- * per page; that container may also `exposes`.
166
- */
167
- provideExternalRuntime?: boolean;
168
- /** Generate the React SSR/hydration island capability for eligible exposes. */
169
- ssrMode?: 'ISLAND';
170
- /**
171
- * The host provides every shared dependency; remotes bring none. Shared keys
172
- * are resolved by a native browser import map instead of the Module
173
- * Federation runtime: the host emits one entry chunk per shared key and
174
- * injects `<script type="importmap">`, remotes keep shared imports as bare
175
- * specifiers and emit one fixed-name entry per expose plus a standard
176
- * `mf-manifest.json` (without `remoteEntry`) the host maps from.
177
- *
178
- * Shared modules become ordinary static ES imports, so there is no
179
- * `loadShare` glue and no `eager` is needed for code that reads a shared
180
- * value at module-evaluation time. There is no version negotiation and no
181
- * runtime API: `requiredVersion`, `strictVersion`, `shareStrategy`,
182
- * `runtimePlugins` and `manifest` are ignored.
183
- *
184
- * @see https://github.com/module-federation/vite/issues/1381
185
- */
186
- hostProvidesAllShared?: boolean;
187
- }
188
- type SsrEntryLoaderStrategy = 'temp-file' | 'vm';
189
- type SsrEntryLoaderConfig = {
190
- /**
191
- * How the auto-injected `@module-federation/vite/ssrEntryLoader` evaluates
192
- * remote SSR entries.
193
- *
194
- * - `'temp-file'` (default when omitted): fetch the ESM graph, rewrite
195
- * specifiers, write temp files and `import()` them.
196
- * - `'vm'`: evaluate the graph with `vm.SourceTextModule`. Requires
197
- * `--experimental-vm-modules`; the loader emits a single warning and
198
- * falls back to `'temp-file'` when that API is unavailable.
199
- */
200
- strategy?: SsrEntryLoaderStrategy;
201
- };
202
- type HostInitInjectLocationOptions = 'entry' | 'html';
203
- interface PluginDevOptions {
204
- disableLiveReload?: boolean;
205
- disableHotTypesReload?: boolean;
206
- disableDynamicRemoteTypeHints?: boolean;
207
- /**
208
- * Controls cross-federation HMR for remote modules.
209
- *
210
- * - `false` / `undefined` — HMR disabled (default).
211
- * - `true` — HMR enabled with auto-detected strategy. When a framework
212
- * plugin with cross-federation HMR support is detected, broadcast/relay
213
- * is suppressed and the framework's native HMR handles updates:
214
- * - React (`@vitejs/plugin-react` / `@vitejs/plugin-react-swc`) — the
215
- * plugin serves a `/@react-refresh` proxy on remotes that delegates
216
- * to the host's `RefreshRuntime`, unifying the component registry.
217
- * - Vue (`@vitejs/plugin-vue` / `@vitejs/plugin-vue-jsx`) — the plugin
218
- * injects a `__VUE_HMR_RUNTIME__` guard into the host page so the
219
- * first-loaded (host) Vue runtime is pinned and remote-loaded Vue
220
- * copies cannot overwrite it.
221
- * For any host, the plugin also injects a script that clears the
222
- * federation `moduleCache` on `vite:beforeUpdate` so subsequent
223
- * `loadRemote()` calls return the freshly patched module.
224
- * Other frameworks fall back to full page reloads.
225
- * - `'full-reload'` — HMR enabled, always use full page reloads even when
226
- * a framework with native cross-federation HMR is detected.
227
- */
228
- remoteHmr?: boolean | 'full-reload';
229
- }
230
- interface RemoteTypeUrl {
231
- alias?: string;
232
- api: string;
233
- zip: string;
234
- }
235
- interface RemoteTypeUrls {
236
- [remoteName: string]: RemoteTypeUrl;
237
- }
238
- interface PluginDtsOptions {
239
- generateTypes?: boolean | DtsRemoteOptions;
240
- consumeTypes?: boolean | DtsHostOptions;
241
- tsConfigPath?: string;
242
- extraOptions?: Record<string, unknown>;
243
- implementation?: string;
244
- cwd?: string;
245
- displayErrorInTerminal?: boolean;
246
- }
247
- interface DtsRemoteOptions {
248
- tsConfigPath?: string;
249
- typesFolder?: string;
250
- compiledTypesFolder?: string;
251
- deleteTypesFolder?: boolean;
252
- additionalFilesToCompile?: string[];
253
- compilerInstance?: 'tsc' | 'vue-tsc' | 'tspc' | string;
254
- compileInChildProcess?: boolean;
255
- generateAPITypes?: boolean;
256
- extractThirdParty?: boolean | {
257
- exclude?: Array<string | RegExp>;
258
- };
259
- extractRemoteTypes?: boolean;
260
- abortOnError?: boolean;
261
- deleteTsConfig?: boolean;
262
- afterGenerate?: (options: moduleFederationPlugin.DtsGenerateTypesHookOptions) => Promise<void> | void;
263
- }
264
- interface DtsHostOptions {
265
- typesFolder?: string;
266
- abortOnError?: boolean;
267
- remoteTypesFolder?: string;
268
- deleteTypesFolder?: boolean;
269
- maxRetries?: number;
270
- consumeAPITypes?: boolean;
271
- runtimePkgs?: string[];
272
- remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
273
- timeout?: number;
274
- family?: 0 | 4 | 6;
275
- typesOnBuild?: boolean;
276
- }
277
- //#endregion
1
+ import { a as SsrEntryLoaderStrategy, i as SsrEntryLoaderConfig, n as PluginExperimentsOptions, o as TreeShakingConfig, r as PluginManifestOptions, t as ModuleFederationOptions } from "./normalizeModuleFederationOptions-DNUlv-AL.js";
278
2
  //#region src/index.d.ts
279
3
  declare function federation(mfUserOptions: ModuleFederationOptions): any[];
280
4
  declare function createModuleFederationConfig<T extends ModuleFederationOptions>(options: T): T;