@module-federation/vite 1.16.16 → 1.17.1
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 +29 -0
- package/lib/index.d.ts +12 -2
- package/lib/index.js +2157 -288
- package/lib/{pluginDts-Bo95ELmX.js → pluginDts-CGDIZCsD.js} +119 -2
- package/lib/ssrEntryLoader-D_sUES94.js +553 -0
- package/lib/{ssrVmStrategy-DtpfkCw1.js → ssrVmStrategy-By_N71Dl.js} +9 -5
- package/lib/utils/ssrEntryLoader.d.ts +5 -0
- package/lib/utils/ssrEntryLoader.js +1 -490
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -238,6 +238,35 @@ const RemoteMFE = defineAsyncComponent( 👈
|
|
|
238
238
|
</template>
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
+
## Shared Tree Shaking
|
|
242
|
+
|
|
243
|
+
Shared Tree Shaking reduces shared dependency bundles to the exports used by the application.
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
federation({
|
|
247
|
+
shared: {
|
|
248
|
+
antd: {
|
|
249
|
+
singleton: true,
|
|
250
|
+
treeShaking: {
|
|
251
|
+
mode: "runtime-infer", // or "server-calc"
|
|
252
|
+
usedExports: ["Button", "Input"],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
treeShakingDir: "independent-packages",
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`runtime-infer` is useful for local development and falls back to the full dependency when the required exports are not available. `server-calc` is recommended for deployments because it can use aggregated export metadata from all consumers.
|
|
261
|
+
|
|
262
|
+
Do not combine `eager: true` with `treeShaking`; eager shared dependencies are bundled into the initial entry and cannot use the on-demand tree-shaking path. Choose eager loading for small dependencies, or tree shaking for larger dependencies such as component libraries.
|
|
263
|
+
|
|
264
|
+
With `server-calc`, the Vite build records the exports used by each application in its generated Module Federation metadata. A deployment service must then collect that metadata for all applications that share the same dependency and version, merge their `usedExports` lists, and use the resulting union to create one optimized secondary shared artifact. For example, if one application uses `Button` and another uses `Input`, the secondary artifact must contain both exports.
|
|
265
|
+
|
|
266
|
+
After creating the secondary artifact, the deployment service must publish it to a location accessible by consumers, such as a CDN, and update the remote Snapshot with the artifact's URL, unique name, and available tree-shaking status. Consumers use those Snapshot fields to decide whether the optimized artifact can satisfy their required exports and version.
|
|
267
|
+
|
|
268
|
+
This deployment step is separate from the local Vite build; the plugin only emits the metadata and runtime support needed by the service. If the Snapshot is not updated, the artifact cannot be fetched, the versions do not match, or the artifact does not provide all required exports, the runtime ignores the optimized artifact and safely loads the complete shared dependency instead.
|
|
269
|
+
|
|
241
270
|
## ⚠️ `codeSplitting` settings are controlled by the plugin
|
|
242
271
|
|
|
243
272
|
Do not set either `build.rollupOptions.output.codeSplitting` or
|
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ interface RemoteObjectConfig {
|
|
|
10
10
|
entryGlobalName?: string;
|
|
11
11
|
shareScope?: string;
|
|
12
12
|
}
|
|
13
|
+
interface TreeShakingConfig {
|
|
14
|
+
mode: 'server-calc' | 'runtime-infer';
|
|
15
|
+
usedExports?: string[];
|
|
16
|
+
}
|
|
13
17
|
interface PluginManifestOptions {
|
|
14
18
|
filePath?: string;
|
|
15
19
|
disableAssetsAnalyze?: boolean;
|
|
@@ -43,14 +47,20 @@ type ModuleFederationOptions = {
|
|
|
43
47
|
* When false (default), the plugin will not process any CSS assets.
|
|
44
48
|
* When true, all CSS assets are bundled into every exposed module.
|
|
45
49
|
*/
|
|
46
|
-
bundleAllCSS?: boolean;
|
|
50
|
+
bundleAllCSS?: boolean; /** Directory reserved for deploy-service generated secondary shared artifacts. */
|
|
51
|
+
treeShakingDir?: string; /** Whether inferred usedExports metadata is injected into generated runtime records. */
|
|
52
|
+
injectTreeShakingUsedExports?: boolean;
|
|
53
|
+
treeShakingSharedPlugins?: string[];
|
|
54
|
+
treeShakingSharedExcludePlugins?: string[];
|
|
47
55
|
shared?: string[] | Record<string, string | {
|
|
48
56
|
name?: string;
|
|
49
57
|
version?: string;
|
|
50
58
|
shareScope?: string;
|
|
51
59
|
singleton?: boolean;
|
|
60
|
+
eager?: boolean;
|
|
52
61
|
requiredVersion?: moduleFederationPlugin.SharedConfig['requiredVersion'];
|
|
53
62
|
strictVersion?: boolean;
|
|
63
|
+
treeShaking?: TreeShakingConfig;
|
|
54
64
|
import?: moduleFederationPlugin.SharedConfig['import'];
|
|
55
65
|
}> | undefined;
|
|
56
66
|
runtimePlugins?: Array<string | [string, Record<string, unknown>]>;
|
|
@@ -172,4 +182,4 @@ interface DtsHostOptions {
|
|
|
172
182
|
declare function federation(mfUserOptions: ModuleFederationOptions): any[];
|
|
173
183
|
declare function createModuleFederationConfig<T extends ModuleFederationOptions>(options: T): T;
|
|
174
184
|
//#endregion
|
|
175
|
-
export { type ModuleFederationOptions, type PluginManifestOptions, createModuleFederationConfig, federation };
|
|
185
|
+
export { type ModuleFederationOptions, type PluginManifestOptions, type TreeShakingConfig, createModuleFederationConfig, federation };
|