@module-federation/rspack 0.0.0-perf-devtools-20260108034446 → 0.0.0-perf-website-code-usage-20260914033703

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.
Files changed (39) hide show
  1. package/dist/{src/ModuleFederationPlugin.d.ts → ModuleFederationPlugin.d.ts} +4 -0
  2. package/dist/ModuleFederationPlugin.js +395 -0
  3. package/dist/{plugin.esm.mjs → ModuleFederationPlugin.mjs} +153 -105
  4. package/dist/RemoteEntryPlugin.js +129 -0
  5. package/dist/{RemoteEntryPlugin.esm.mjs → RemoteEntryPlugin.mjs} +16 -21
  6. package/dist/TreeShakingSharedPlugin.d.ts +13 -0
  7. package/dist/TreeShakingSharedPlugin.js +67 -0
  8. package/dist/TreeShakingSharedPlugin.mjs +13 -0
  9. package/dist/index.d.ts +4 -1
  10. package/dist/index.js +71 -0
  11. package/dist/{index.esm.mjs → index.mjs} +6 -3
  12. package/dist/logger.js +64 -0
  13. package/dist/logger.mjs +10 -0
  14. package/dist/plugin.d.ts +1 -1
  15. package/dist/plugin.js +96 -0
  16. package/dist/plugin.mjs +4 -0
  17. package/dist/remote-entry-plugin.d.ts +1 -1
  18. package/dist/remote-entry-plugin.js +96 -0
  19. package/dist/remote-entry-plugin.mjs +4 -0
  20. package/package.json +45 -23
  21. package/dist/RemoteEntryPlugin.cjs.js +0 -70
  22. package/dist/RemoteEntryPlugin.cjs.js.map +0 -1
  23. package/dist/RemoteEntryPlugin.esm.mjs.map +0 -1
  24. package/dist/index.cjs.js +0 -13
  25. package/dist/index.cjs.js.map +0 -1
  26. package/dist/index.esm.d.ts +0 -1
  27. package/dist/index.esm.mjs.map +0 -1
  28. package/dist/plugin.cjs.js +0 -271
  29. package/dist/plugin.cjs.js.map +0 -1
  30. package/dist/plugin.esm.d.ts +0 -1
  31. package/dist/plugin.esm.mjs.map +0 -1
  32. package/dist/remote-entry-plugin.cjs.js +0 -10
  33. package/dist/remote-entry-plugin.cjs.js.map +0 -1
  34. package/dist/remote-entry-plugin.esm.d.ts +0 -1
  35. package/dist/remote-entry-plugin.esm.mjs +0 -4
  36. package/dist/remote-entry-plugin.esm.mjs.map +0 -1
  37. package/dist/src/index.d.ts +0 -3
  38. /package/dist/{src/RemoteEntryPlugin.d.ts → RemoteEntryPlugin.d.ts} +0 -0
  39. /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
@@ -2,6 +2,9 @@ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
2
  import { moduleFederationPlugin } from '@module-federation/sdk';
3
3
  import { RemoteEntryPlugin } from './RemoteEntryPlugin';
4
4
  export declare const PLUGIN_NAME = "RspackModuleFederationPlugin";
5
+ type ResolveFn = typeof require.resolve;
6
+ export declare function resolveRspackRuntimeImplementation(implementation?: string, resolve?: ResolveFn): string;
7
+ export declare function resolveRspackRuntimeAlias(implementation: string, resolve?: ResolveFn): string;
5
8
  export declare class ModuleFederationPlugin implements RspackPluginInstance {
6
9
  readonly name = "RspackModuleFederationPlugin";
7
10
  private _options;
@@ -13,3 +16,4 @@ export declare class ModuleFederationPlugin implements RspackPluginInstance {
13
16
  private _patchChunkSplit;
14
17
  }
15
18
  export declare const GetPublicPathPlugin: typeof RemoteEntryPlugin;
19
+ export { TreeShakingSharedPlugin, type TreeShakingSharedPluginOptions, } from './TreeShakingSharedPlugin';
@@ -0,0 +1,395 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ // webpack/runtime/compat_get_default_export
13
+ (() => {
14
+ // getDefaultExport function for compatibility with non-ESM modules
15
+ __webpack_require__.n = (module) => {
16
+ var getter = module && module.__esModule ?
17
+ () => (module['default']) :
18
+ () => (module);
19
+ __webpack_require__.d(getter, { a: getter });
20
+ return getter;
21
+ };
22
+
23
+ })();
24
+ // webpack/runtime/define_property_getters
25
+ (() => {
26
+ __webpack_require__.d = (exports, getters, values) => {
27
+ var define = (defs, kind) => {
28
+ for(var key in defs) {
29
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
31
+ }
32
+ }
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ // webpack/runtime/has_own_property
39
+ (() => {
40
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
41
+ })();
42
+ // webpack/runtime/make_namespace_object
43
+ (() => {
44
+ // define __esModule on exports
45
+ __webpack_require__.r = (exports) => {
46
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ }
49
+ Object.defineProperty(exports, '__esModule', { value: true });
50
+ };
51
+ })();
52
+ var __webpack_exports__ = {};
53
+ // ESM COMPAT FLAG
54
+ __webpack_require__.r(__webpack_exports__);
55
+
56
+ // EXPORTS
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ GetPublicPathPlugin: () => (/* binding */ GetPublicPathPlugin),
59
+ ModuleFederationPlugin: () => (/* binding */ ModuleFederationPlugin),
60
+ PLUGIN_NAME: () => (/* binding */ PLUGIN_NAME),
61
+ TreeShakingSharedPlugin: () => (/* reexport */ external_TreeShakingSharedPlugin_js_namespaceObject.TreeShakingSharedPlugin),
62
+ resolveRspackRuntimeAlias: () => (/* binding */ resolveRspackRuntimeAlias),
63
+ resolveRspackRuntimeImplementation: () => (/* binding */ resolveRspackRuntimeImplementation)
64
+ });
65
+
66
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
67
+ const sdk_namespaceObject = require("@module-federation/sdk");
68
+ ;// CONCATENATED MODULE: external "@module-federation/manifest"
69
+ const manifest_namespaceObject = require("@module-federation/manifest");
70
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
71
+ const managers_namespaceObject = require("@module-federation/managers");
72
+ ;// CONCATENATED MODULE: external "@module-federation/dts-plugin"
73
+ const dts_plugin_namespaceObject = require("@module-federation/dts-plugin");
74
+ ;// CONCATENATED MODULE: external "@module-federation/bridge-react-webpack-plugin"
75
+ const bridge_react_webpack_plugin_namespaceObject = require("@module-federation/bridge-react-webpack-plugin");
76
+ var bridge_react_webpack_plugin_default = /*#__PURE__*/__webpack_require__.n(bridge_react_webpack_plugin_namespaceObject);
77
+ ;// CONCATENATED MODULE: external "node:path"
78
+ const external_node_path_namespaceObject = require("node:path");
79
+ var external_node_path_default = /*#__PURE__*/__webpack_require__.n(external_node_path_namespaceObject);
80
+ ;// CONCATENATED MODULE: external "node:fs"
81
+ const external_node_fs_namespaceObject = require("node:fs");
82
+ var external_node_fs_default = /*#__PURE__*/__webpack_require__.n(external_node_fs_namespaceObject);
83
+ ;// CONCATENATED MODULE: external "./RemoteEntryPlugin.js"
84
+ const external_RemoteEntryPlugin_js_namespaceObject = require("./RemoteEntryPlugin.js");
85
+ ;// CONCATENATED MODULE: external "./logger.js"
86
+ const external_logger_js_namespaceObject = require("./logger.js");
87
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
88
+ ;// CONCATENATED MODULE: external "./TreeShakingSharedPlugin.js"
89
+ const external_TreeShakingSharedPlugin_js_namespaceObject = require("./TreeShakingSharedPlugin.js");
90
+ ;// CONCATENATED MODULE: ./src/ModuleFederationPlugin.ts
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ const PLUGIN_NAME = 'RspackModuleFederationPlugin';
101
+ function hasExposes(exposes) {
102
+ return Boolean(exposes && (Array.isArray(exposes) ? exposes.length > 0 : Object.keys(exposes).length > 0));
103
+ }
104
+ function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
105
+ const candidates = [
106
+ spec.bundler,
107
+ spec.esm,
108
+ spec.cjs
109
+ ];
110
+ const modulePaths = implementation ? [
111
+ implementation
112
+ ] : undefined;
113
+ let lastError;
114
+ for (const candidate of candidates){
115
+ try {
116
+ return modulePaths ? resolve(candidate, {
117
+ paths: modulePaths
118
+ }) : resolve(candidate);
119
+ } catch (error) {
120
+ lastError = error;
121
+ }
122
+ }
123
+ throw lastError;
124
+ }
125
+ function resolveRspackRuntimeImplementation(implementation, resolve = require.resolve) {
126
+ return resolveRuntimeEntry({
127
+ bundler: '@module-federation/runtime-tools/bundler',
128
+ esm: '@module-federation/runtime-tools/dist/index.js',
129
+ cjs: '@module-federation/runtime-tools/dist/index.cjs'
130
+ }, implementation, resolve);
131
+ }
132
+ function resolveRspackRuntimeAlias(implementation, resolve = require.resolve) {
133
+ return resolveRuntimeEntry({
134
+ bundler: '@module-federation/runtime/bundler',
135
+ esm: '@module-federation/runtime/dist/index.js',
136
+ cjs: '@module-federation/runtime/dist/index.cjs'
137
+ }, implementation, resolve);
138
+ }
139
+ class ModuleFederationPlugin {
140
+ _patchBundlerConfig(compiler) {
141
+ const { name, experiments, exposes } = this._options;
142
+ const definePluginOptions = {};
143
+ if (name) {
144
+ definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify((0,sdk_namespaceObject.composeKeyWithSeparator)(name, managers_namespaceObject.utils.getBuildVersion()));
145
+ }
146
+ // Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
147
+ const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;
148
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] = disableSnapshot;
149
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_REMOTE'] = experiments?.optimization?.disableRemote ?? false;
150
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SHARED'] = experiments?.optimization?.disableShared ?? false;
151
+ definePluginOptions['FEDERATION_HAS_EXPOSES'] = hasExposes(exposes);
152
+ // Determine ENV_TARGET: only if manually specified in experiments.optimization.target
153
+ if (experiments?.optimization && typeof experiments.optimization === 'object' && experiments.optimization !== null && 'target' in experiments.optimization) {
154
+ const manualTarget = experiments.optimization.target;
155
+ // Ensure the target is one of the expected values before setting
156
+ if (manualTarget === 'web' || manualTarget === 'node') {
157
+ definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);
158
+ }
159
+ }
160
+ // No inference for ENV_TARGET. If not manually set and valid, it's not defined.
161
+ new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
162
+ }
163
+ _checkSingleton(compiler) {
164
+ let count = 0;
165
+ compiler.options.plugins.forEach((p)=>{
166
+ if (typeof p !== 'object' || !p) {
167
+ return;
168
+ }
169
+ if (p['name'] === this.name) {
170
+ count++;
171
+ if (count > 1) {
172
+ throw new Error(`Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`);
173
+ }
174
+ }
175
+ });
176
+ }
177
+ apply(compiler) {
178
+ (0,sdk_namespaceObject.bindLoggerToCompiler)((external_logger_js_default()), compiler, PLUGIN_NAME);
179
+ const { _options: options } = this;
180
+ if (!options.name) {
181
+ throw new Error('[ ModuleFederationPlugin ]: name is required');
182
+ }
183
+ this._checkSingleton(compiler);
184
+ this._patchBundlerConfig(compiler);
185
+ const containerManager = new managers_namespaceObject.ContainerManager();
186
+ containerManager.init(options);
187
+ if (containerManager.enable) {
188
+ this._patchChunkSplit(compiler, options.name);
189
+ }
190
+ // must before ModuleFederationPlugin
191
+ new external_RemoteEntryPlugin_js_namespaceObject.RemoteEntryPlugin(options).apply(compiler);
192
+ if (options.experiments?.provideExternalRuntime) {
193
+ if (containerManager.enable) {
194
+ throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
195
+ }
196
+ const runtimePlugins = options.runtimePlugins || [];
197
+ options.runtimePlugins = runtimePlugins.concat(require.resolve('@module-federation/inject-external-runtime-core-plugin'));
198
+ }
199
+ if (options.experiments?.externalRuntime === true) {
200
+ const Externals = compiler.webpack.ExternalsPlugin;
201
+ new Externals(compiler.options.externalsType || 'global', {
202
+ '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
203
+ }).apply(compiler);
204
+ }
205
+ const implementationPath = options.implementation ? options.implementation : resolveRspackRuntimeImplementation();
206
+ options.implementation = implementationPath;
207
+ let disableManifest = options.manifest === false;
208
+ let disableDts = options.dts === false;
209
+ if (!disableDts) {
210
+ const dtsPlugin = new dts_plugin_namespaceObject.DtsPlugin(options);
211
+ // @ts-ignore
212
+ dtsPlugin.apply(compiler);
213
+ dtsPlugin.addRuntimePlugins();
214
+ }
215
+ if (!disableManifest && options.exposes) {
216
+ try {
217
+ options.exposes = containerManager.containerPluginExposesOptions;
218
+ } catch (err) {
219
+ if (err instanceof Error) {
220
+ err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;
221
+ }
222
+ external_logger_js_default().warn(err);
223
+ disableManifest = true;
224
+ }
225
+ }
226
+ new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
227
+ let runtimePath;
228
+ try {
229
+ runtimePath = resolveRspackRuntimeAlias(implementationPath);
230
+ } catch (err) {
231
+ const detail = err instanceof Error ? err.message : String(err);
232
+ throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry (paths: [${implementationPath}]): ${detail}`);
233
+ }
234
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', ()=>{
235
+ compiler.options.resolve.alias = {
236
+ ...compiler.options.resolve.alias,
237
+ '@module-federation/runtime$': runtimePath
238
+ };
239
+ });
240
+ if (!disableManifest) {
241
+ this._statsPlugin = new manifest_namespaceObject.StatsPlugin(options, {
242
+ pluginVersion: "0.0.0-perf-website-code-usage-20260914033703",
243
+ bundler: 'rspack'
244
+ });
245
+ // @ts-ignore
246
+ this._statsPlugin.apply(compiler);
247
+ }
248
+ const checkBridgeReactInstalled = ()=>{
249
+ try {
250
+ const userPackageJsonPath = external_node_path_default().resolve(compiler.context, 'package.json');
251
+ if (external_node_fs_default().existsSync(userPackageJsonPath)) {
252
+ const userPackageJson = JSON.parse(external_node_fs_default().readFileSync(userPackageJsonPath, 'utf-8'));
253
+ const userDependencies = {
254
+ ...userPackageJson.dependencies,
255
+ ...userPackageJson.devDependencies
256
+ };
257
+ return !!userDependencies['@module-federation/bridge-react'];
258
+ }
259
+ return false;
260
+ } catch (error) {
261
+ return false;
262
+ }
263
+ };
264
+ const hasBridgeReact = checkBridgeReactInstalled();
265
+ // react bridge plugin
266
+ const shouldEnableBridgePlugin = ()=>{
267
+ // Priority 1: Explicit enableBridgeRouter configuration
268
+ if (options?.bridge?.enableBridgeRouter === true) {
269
+ return true;
270
+ }
271
+ // Priority 2: Explicit disable via enableBridgeRouter:false or disableAlias:true
272
+ if (options?.bridge?.enableBridgeRouter === false || options?.bridge?.disableAlias === true) {
273
+ if (options?.bridge?.disableAlias === true) {
274
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] The `disableAlias` option is deprecated and will be removed in a future version.\n' + ' Please use `enableBridgeRouter: false` instead:\n' + ' {\n' + ' bridge: {\n' + ' enableBridgeRouter: false // Use this instead of disableAlias: true\n' + ' }\n' + ' }');
275
+ }
276
+ return false;
277
+ }
278
+ // Priority 3: Automatic detection based on bridge-react installation
279
+ if (hasBridgeReact) {
280
+ external_logger_js_default().info('💡 [ModuleFederationPlugin] Detected @module-federation/bridge-react in your dependencies.\n' + ' For better control and to avoid future breaking changes, please explicitly set:\n' + ' {\n' + ' bridge: {\n' + ' enableBridgeRouter: true // Explicitly enable bridge router\n' + ' }\n' + ' }');
281
+ return true;
282
+ }
283
+ return false;
284
+ };
285
+ const enableBridgePlugin = shouldEnableBridgePlugin();
286
+ // When bridge plugin is disabled (router disabled), alias to /base entry
287
+ if (!enableBridgePlugin && hasBridgeReact) {
288
+ compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', ()=>{
289
+ try {
290
+ const bridgeReactBasePath = external_node_path_default().resolve(compiler.context, 'node_modules/@module-federation/bridge-react/dist/base.es.js');
291
+ if (!external_node_fs_default().existsSync(bridgeReactBasePath)) {
292
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] bridge-react /base entry not found, falling back to default entry');
293
+ return;
294
+ }
295
+ compiler.options.resolve.alias = {
296
+ ...compiler.options.resolve.alias,
297
+ '@module-federation/bridge-react$': bridgeReactBasePath
298
+ };
299
+ external_logger_js_default().info('✅ [ModuleFederationPlugin] Router disabled - using /base entry (no react-router-dom)');
300
+ } catch (error) {
301
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] Failed to set /base alias, using default entry');
302
+ }
303
+ });
304
+ }
305
+ if (enableBridgePlugin) {
306
+ new (bridge_react_webpack_plugin_default())({
307
+ moduleFederationOptions: this._options
308
+ }).apply(compiler);
309
+ }
310
+ }
311
+ _patchChunkSplit(compiler, name) {
312
+ const { splitChunks } = compiler.options.optimization;
313
+ const patchChunkSplit = (cacheGroup)=>{
314
+ switch(typeof cacheGroup){
315
+ case 'boolean':
316
+ case 'string':
317
+ case 'function':
318
+ break;
319
+ // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
320
+ case 'object':
321
+ {
322
+ if (cacheGroup instanceof RegExp) {
323
+ break;
324
+ }
325
+ if (!cacheGroup.chunks) {
326
+ break;
327
+ }
328
+ if (typeof cacheGroup.chunks === 'function') {
329
+ const prevChunks = cacheGroup.chunks;
330
+ cacheGroup.chunks = (chunk)=>{
331
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
332
+ return false;
333
+ }
334
+ return prevChunks(chunk);
335
+ };
336
+ break;
337
+ }
338
+ if (cacheGroup.chunks === 'all') {
339
+ cacheGroup.chunks = (chunk)=>{
340
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
341
+ return false;
342
+ }
343
+ return true;
344
+ };
345
+ break;
346
+ }
347
+ if (cacheGroup.chunks === 'initial') {
348
+ cacheGroup.chunks = (chunk)=>{
349
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
350
+ return false;
351
+ }
352
+ return chunk.isOnlyInitial();
353
+ };
354
+ break;
355
+ }
356
+ break;
357
+ }
358
+ default:
359
+ break;
360
+ }
361
+ };
362
+ if (!splitChunks) {
363
+ return;
364
+ }
365
+ // 修改 splitChunk.chunks
366
+ patchChunkSplit(splitChunks);
367
+ const { cacheGroups } = splitChunks;
368
+ if (!cacheGroups) {
369
+ return;
370
+ }
371
+ // 修改 splitChunk.cacheGroups[key].chunks
372
+ Object.keys(cacheGroups).forEach((cacheGroupKey)=>{
373
+ patchChunkSplit(cacheGroups[cacheGroupKey]);
374
+ });
375
+ }
376
+ constructor(options){
377
+ this.name = PLUGIN_NAME;
378
+ this._options = options;
379
+ }
380
+ }
381
+ const GetPublicPathPlugin = external_RemoteEntryPlugin_js_namespaceObject.RemoteEntryPlugin;
382
+
383
+
384
+ exports.GetPublicPathPlugin = __webpack_exports__.GetPublicPathPlugin;
385
+ exports.ModuleFederationPlugin = __webpack_exports__.ModuleFederationPlugin;
386
+ exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
387
+ exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
388
+ exports.resolveRspackRuntimeAlias = __webpack_exports__.resolveRspackRuntimeAlias;
389
+ exports.resolveRspackRuntimeImplementation = __webpack_exports__.resolveRspackRuntimeImplementation;
390
+ for(var __rspack_i in __webpack_exports__) {
391
+ if(["GetPublicPathPlugin","ModuleFederationPlugin","PLUGIN_NAME","TreeShakingSharedPlugin","resolveRspackRuntimeAlias","resolveRspackRuntimeImplementation"].indexOf(__rspack_i) === -1) {
392
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
393
+ }
394
+ }
395
+ Object.defineProperty(exports, '__esModule', { value: true });