@module-federation/rspack 0.0.0-perf-devtools-20260107043700 → 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
@@ -1,34 +1,86 @@
1
- import { composeKeyWithSeparator, bindLoggerToCompiler } from '@module-federation/sdk';
2
- import { StatsPlugin } from '@module-federation/manifest';
3
- import { utils, ContainerManager } from '@module-federation/managers';
4
- import { DtsPlugin } from '@module-federation/dts-plugin';
5
- import ReactBridgePlugin from '@module-federation/bridge-react-webpack-plugin';
6
- import path from 'node:path';
7
- import fs from 'node:fs';
8
- import { R as RemoteEntryPlugin, l as logger } from './RemoteEntryPlugin.esm.mjs';
1
+ import { bindLoggerToCompiler, composeKeyWithSeparator } from "@module-federation/sdk";
2
+ import { StatsPlugin } from "@module-federation/manifest";
3
+ import { ContainerManager, utils } from "@module-federation/managers";
4
+ import { DtsPlugin } from "@module-federation/dts-plugin";
5
+ import bridge_react_webpack_plugin from "@module-federation/bridge-react-webpack-plugin";
6
+ import node_path from "node:path";
7
+ import node_fs from "node:fs";
8
+ import { RemoteEntryPlugin } from "./RemoteEntryPlugin.mjs";
9
+ import logger from "./logger.mjs";
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
9
29
 
10
- const RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
11
30
  const PLUGIN_NAME = 'RspackModuleFederationPlugin';
12
- class ModuleFederationPlugin {
13
- constructor(options) {
14
- this.name = PLUGIN_NAME;
15
- this._options = options;
31
+ function hasExposes(exposes) {
32
+ return Boolean(exposes && (Array.isArray(exposes) ? exposes.length > 0 : Object.keys(exposes).length > 0));
33
+ }
34
+ function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
35
+ const candidates = [
36
+ spec.bundler,
37
+ spec.esm,
38
+ spec.cjs
39
+ ];
40
+ const modulePaths = implementation ? [
41
+ implementation
42
+ ] : undefined;
43
+ let lastError;
44
+ for (const candidate of candidates){
45
+ try {
46
+ return modulePaths ? resolve(candidate, {
47
+ paths: modulePaths
48
+ }) : resolve(candidate);
49
+ } catch (error) {
50
+ lastError = error;
51
+ }
16
52
  }
53
+ throw lastError;
54
+ }
55
+ function resolveRspackRuntimeImplementation(implementation, resolve = require.resolve) {
56
+ return resolveRuntimeEntry({
57
+ bundler: '@module-federation/runtime-tools/bundler',
58
+ esm: '@module-federation/runtime-tools/dist/index.js',
59
+ cjs: '@module-federation/runtime-tools/dist/index.cjs'
60
+ }, implementation, resolve);
61
+ }
62
+ function resolveRspackRuntimeAlias(implementation, resolve = require.resolve) {
63
+ return resolveRuntimeEntry({
64
+ bundler: '@module-federation/runtime/bundler',
65
+ esm: '@module-federation/runtime/dist/index.js',
66
+ cjs: '@module-federation/runtime/dist/index.cjs'
67
+ }, implementation, resolve);
68
+ }
69
+ class ModuleFederationPlugin {
17
70
  _patchBundlerConfig(compiler) {
18
- const { name, experiments } = this._options;
71
+ const { name, experiments, exposes } = this._options;
19
72
  const definePluginOptions = {};
20
73
  if (name) {
21
74
  definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(composeKeyWithSeparator(name, utils.getBuildVersion()));
22
75
  }
23
76
  // Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
24
77
  const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;
25
- definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] =
26
- disableSnapshot;
78
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] = disableSnapshot;
79
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_REMOTE'] = experiments?.optimization?.disableRemote ?? false;
80
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SHARED'] = experiments?.optimization?.disableShared ?? false;
81
+ definePluginOptions['FEDERATION_HAS_EXPOSES'] = hasExposes(exposes);
27
82
  // Determine ENV_TARGET: only if manually specified in experiments.optimization.target
28
- if (experiments?.optimization &&
29
- typeof experiments.optimization === 'object' &&
30
- experiments.optimization !== null &&
31
- 'target' in experiments.optimization) {
83
+ if (experiments?.optimization && typeof experiments.optimization === 'object' && experiments.optimization !== null && 'target' in experiments.optimization) {
32
84
  const manualTarget = experiments.optimization.target;
33
85
  // Ensure the target is one of the expected values before setting
34
86
  if (manualTarget === 'web' || manualTarget === 'node') {
@@ -40,7 +92,7 @@ class ModuleFederationPlugin {
40
92
  }
41
93
  _checkSingleton(compiler) {
42
94
  let count = 0;
43
- compiler.options.plugins.forEach((p) => {
95
+ compiler.options.plugins.forEach((p)=>{
44
96
  if (typeof p !== 'object' || !p) {
45
97
  return;
46
98
  }
@@ -68,7 +120,7 @@ class ModuleFederationPlugin {
68
120
  // must before ModuleFederationPlugin
69
121
  new RemoteEntryPlugin(options).apply(compiler);
70
122
  if (options.experiments?.provideExternalRuntime) {
71
- if (options.exposes) {
123
+ if (containerManager.enable) {
72
124
  throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
73
125
  }
74
126
  const runtimePlugins = options.runtimePlugins || [];
@@ -77,10 +129,11 @@ class ModuleFederationPlugin {
77
129
  if (options.experiments?.externalRuntime === true) {
78
130
  const Externals = compiler.webpack.ExternalsPlugin;
79
131
  new Externals(compiler.options.externalsType || 'global', {
80
- '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE',
132
+ '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
81
133
  }).apply(compiler);
82
134
  }
83
- options.implementation = options.implementation || RuntimeToolsPath;
135
+ const implementationPath = options.implementation ? options.implementation : resolveRspackRuntimeImplementation();
136
+ options.implementation = implementationPath;
84
137
  let disableManifest = options.manifest === false;
85
138
  let disableDts = options.dts === false;
86
139
  if (!disableDts) {
@@ -92,8 +145,7 @@ class ModuleFederationPlugin {
92
145
  if (!disableManifest && options.exposes) {
93
146
  try {
94
147
  options.exposes = containerManager.containerPluginExposesOptions;
95
- }
96
- catch (err) {
148
+ } catch (err) {
97
149
  if (err instanceof Error) {
98
150
  err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;
99
151
  }
@@ -102,68 +154,60 @@ class ModuleFederationPlugin {
102
154
  }
103
155
  }
104
156
  new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
105
- const runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.js', { paths: [options.implementation] });
106
- compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', () => {
157
+ let runtimePath;
158
+ try {
159
+ runtimePath = resolveRspackRuntimeAlias(implementationPath);
160
+ } catch (err) {
161
+ const detail = err instanceof Error ? err.message : String(err);
162
+ throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry (paths: [${implementationPath}]): ${detail}`);
163
+ }
164
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', ()=>{
107
165
  compiler.options.resolve.alias = {
108
166
  ...compiler.options.resolve.alias,
109
- '@module-federation/runtime$': runtimeESMPath,
167
+ '@module-federation/runtime$': runtimePath
110
168
  };
111
169
  });
112
170
  if (!disableManifest) {
113
171
  this._statsPlugin = new StatsPlugin(options, {
114
- pluginVersion: "0.0.0-perf-devtools-20260107043700",
115
- bundler: 'rspack',
172
+ pluginVersion: "0.0.0-perf-website-code-usage-20260914033703",
173
+ bundler: 'rspack'
116
174
  });
117
175
  // @ts-ignore
118
176
  this._statsPlugin.apply(compiler);
119
177
  }
120
- const checkBridgeReactInstalled = () => {
178
+ const checkBridgeReactInstalled = ()=>{
121
179
  try {
122
- const userPackageJsonPath = path.resolve(compiler.context, 'package.json');
123
- if (fs.existsSync(userPackageJsonPath)) {
124
- const userPackageJson = JSON.parse(fs.readFileSync(userPackageJsonPath, 'utf-8'));
180
+ const userPackageJsonPath = node_path.resolve(compiler.context, 'package.json');
181
+ if (node_fs.existsSync(userPackageJsonPath)) {
182
+ const userPackageJson = JSON.parse(node_fs.readFileSync(userPackageJsonPath, 'utf-8'));
125
183
  const userDependencies = {
126
184
  ...userPackageJson.dependencies,
127
- ...userPackageJson.devDependencies,
185
+ ...userPackageJson.devDependencies
128
186
  };
129
187
  return !!userDependencies['@module-federation/bridge-react'];
130
188
  }
131
189
  return false;
132
- }
133
- catch (error) {
190
+ } catch (error) {
134
191
  return false;
135
192
  }
136
193
  };
137
194
  const hasBridgeReact = checkBridgeReactInstalled();
138
195
  // react bridge plugin
139
- const shouldEnableBridgePlugin = () => {
196
+ const shouldEnableBridgePlugin = ()=>{
140
197
  // Priority 1: Explicit enableBridgeRouter configuration
141
198
  if (options?.bridge?.enableBridgeRouter === true) {
142
199
  return true;
143
200
  }
144
201
  // Priority 2: Explicit disable via enableBridgeRouter:false or disableAlias:true
145
- if (options?.bridge?.enableBridgeRouter === false ||
146
- options?.bridge?.disableAlias === true) {
202
+ if (options?.bridge?.enableBridgeRouter === false || options?.bridge?.disableAlias === true) {
147
203
  if (options?.bridge?.disableAlias === true) {
148
- logger.warn('⚠️ [ModuleFederationPlugin] The `disableAlias` option is deprecated and will be removed in a future version.\n' +
149
- ' Please use `enableBridgeRouter: false` instead:\n' +
150
- ' {\n' +
151
- ' bridge: {\n' +
152
- ' enableBridgeRouter: false // Use this instead of disableAlias: true\n' +
153
- ' }\n' +
154
- ' }');
204
+ logger.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' + ' }');
155
205
  }
156
206
  return false;
157
207
  }
158
208
  // Priority 3: Automatic detection based on bridge-react installation
159
209
  if (hasBridgeReact) {
160
- logger.info('💡 [ModuleFederationPlugin] Detected @module-federation/bridge-react in your dependencies.\n' +
161
- ' For better control and to avoid future breaking changes, please explicitly set:\n' +
162
- ' {\n' +
163
- ' bridge: {\n' +
164
- ' enableBridgeRouter: true // Explicitly enable bridge router\n' +
165
- ' }\n' +
166
- ' }');
210
+ logger.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' + ' }');
167
211
  return true;
168
212
  }
169
213
  return false;
@@ -171,79 +215,78 @@ class ModuleFederationPlugin {
171
215
  const enableBridgePlugin = shouldEnableBridgePlugin();
172
216
  // When bridge plugin is disabled (router disabled), alias to /base entry
173
217
  if (!enableBridgePlugin && hasBridgeReact) {
174
- compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', () => {
218
+ compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', ()=>{
175
219
  try {
176
- const bridgeReactBasePath = path.resolve(compiler.context, 'node_modules/@module-federation/bridge-react/dist/base.es.js');
177
- if (!fs.existsSync(bridgeReactBasePath)) {
220
+ const bridgeReactBasePath = node_path.resolve(compiler.context, 'node_modules/@module-federation/bridge-react/dist/base.es.js');
221
+ if (!node_fs.existsSync(bridgeReactBasePath)) {
178
222
  logger.warn('⚠️ [ModuleFederationPlugin] bridge-react /base entry not found, falling back to default entry');
179
223
  return;
180
224
  }
181
225
  compiler.options.resolve.alias = {
182
226
  ...compiler.options.resolve.alias,
183
- '@module-federation/bridge-react$': bridgeReactBasePath,
227
+ '@module-federation/bridge-react$': bridgeReactBasePath
184
228
  };
185
229
  logger.info('✅ [ModuleFederationPlugin] Router disabled - using /base entry (no react-router-dom)');
186
- }
187
- catch (error) {
230
+ } catch (error) {
188
231
  logger.warn('⚠️ [ModuleFederationPlugin] Failed to set /base alias, using default entry');
189
232
  }
190
233
  });
191
234
  }
192
235
  if (enableBridgePlugin) {
193
- new ReactBridgePlugin({
194
- moduleFederationOptions: this._options,
236
+ new bridge_react_webpack_plugin({
237
+ moduleFederationOptions: this._options
195
238
  }).apply(compiler);
196
239
  }
197
240
  }
198
241
  _patchChunkSplit(compiler, name) {
199
242
  const { splitChunks } = compiler.options.optimization;
200
- const patchChunkSplit = (cacheGroup) => {
201
- switch (typeof cacheGroup) {
243
+ const patchChunkSplit = (cacheGroup)=>{
244
+ switch(typeof cacheGroup){
202
245
  case 'boolean':
203
246
  case 'string':
204
247
  case 'function':
205
248
  break;
206
249
  // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
207
- case 'object': {
208
- if (cacheGroup instanceof RegExp) {
209
- break;
210
- }
211
- if (!cacheGroup.chunks) {
212
- break;
213
- }
214
- if (typeof cacheGroup.chunks === 'function') {
215
- const prevChunks = cacheGroup.chunks;
216
- cacheGroup.chunks = (chunk) => {
217
- if (chunk.name &&
218
- (chunk.name === name || chunk.name === name + '_partial')) {
219
- return false;
220
- }
221
- return prevChunks(chunk);
222
- };
223
- break;
224
- }
225
- if (cacheGroup.chunks === 'all') {
226
- cacheGroup.chunks = (chunk) => {
227
- if (chunk.name &&
228
- (chunk.name === name || chunk.name === name + '_partial')) {
229
- return false;
230
- }
231
- return true;
232
- };
233
- break;
234
- }
235
- if (cacheGroup.chunks === 'initial') {
236
- cacheGroup.chunks = (chunk) => {
237
- if (chunk.name &&
238
- (chunk.name === name || chunk.name === name + '_partial')) {
239
- return false;
240
- }
241
- return chunk.isOnlyInitial();
242
- };
250
+ case 'object':
251
+ {
252
+ if (cacheGroup instanceof RegExp) {
253
+ break;
254
+ }
255
+ if (!cacheGroup.chunks) {
256
+ break;
257
+ }
258
+ if (typeof cacheGroup.chunks === 'function') {
259
+ const prevChunks = cacheGroup.chunks;
260
+ cacheGroup.chunks = (chunk)=>{
261
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
262
+ return false;
263
+ }
264
+ return prevChunks(chunk);
265
+ };
266
+ break;
267
+ }
268
+ if (cacheGroup.chunks === 'all') {
269
+ cacheGroup.chunks = (chunk)=>{
270
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
271
+ return false;
272
+ }
273
+ return true;
274
+ };
275
+ break;
276
+ }
277
+ if (cacheGroup.chunks === 'initial') {
278
+ cacheGroup.chunks = (chunk)=>{
279
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
280
+ return false;
281
+ }
282
+ return chunk.isOnlyInitial();
283
+ };
284
+ break;
285
+ }
243
286
  break;
244
287
  }
288
+ default:
245
289
  break;
246
- }
247
290
  }
248
291
  };
249
292
  if (!splitChunks) {
@@ -256,12 +299,17 @@ class ModuleFederationPlugin {
256
299
  return;
257
300
  }
258
301
  // 修改 splitChunk.cacheGroups[key].chunks
259
- Object.keys(cacheGroups).forEach((cacheGroupKey) => {
302
+ Object.keys(cacheGroups).forEach((cacheGroupKey)=>{
260
303
  patchChunkSplit(cacheGroups[cacheGroupKey]);
261
304
  });
262
305
  }
306
+ constructor(options){
307
+ this.name = PLUGIN_NAME;
308
+ this._options = options;
309
+ }
263
310
  }
264
311
  const GetPublicPathPlugin = RemoteEntryPlugin;
265
312
 
266
- export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME };
267
- //# sourceMappingURL=plugin.esm.mjs.map
313
+
314
+ export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME, resolveRspackRuntimeAlias, resolveRspackRuntimeImplementation };
315
+ export { TreeShakingSharedPlugin } from "./TreeShakingSharedPlugin.mjs";
@@ -0,0 +1,129 @@
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
+ RemoteEntryPlugin: () => (/* binding */ RemoteEntryPlugin)
59
+ });
60
+
61
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
62
+ const managers_namespaceObject = require("@module-federation/managers");
63
+ ;// CONCATENATED MODULE: external "./logger.js"
64
+ const external_logger_js_namespaceObject = require("./logger.js");
65
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
66
+ ;// CONCATENATED MODULE: ./src/RemoteEntryPlugin.ts
67
+
68
+
69
+ // @ts-ignore
70
+ const charMap = {
71
+ '<': '\\u003C',
72
+ '>': '\\u003E',
73
+ '/': '\\u002F',
74
+ '\\': '\\\\',
75
+ '\b': '\\b',
76
+ '\f': '\\f',
77
+ '\n': '\\n',
78
+ '\r': '\\r',
79
+ '\t': '\\t',
80
+ '\0': '\\0',
81
+ '\u2028': '\\u2028',
82
+ '\u2029': '\\u2029'
83
+ };
84
+ function escapeUnsafeChars(str) {
85
+ return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x)=>charMap[x]);
86
+ }
87
+ class RemoteEntryPlugin {
88
+ static addPublicPathEntry(compiler, getPublicPath, name) {
89
+ let code;
90
+ const sanitizedPublicPath = escapeUnsafeChars(getPublicPath);
91
+ if (!getPublicPath.startsWith('function')) {
92
+ code = `${compiler.webpack.RuntimeGlobals.publicPath} = new Function(${JSON.stringify(sanitizedPublicPath)})()`;
93
+ } else {
94
+ code = `(${sanitizedPublicPath}())`;
95
+ }
96
+ const base64Code = Buffer.from(code, 'utf8').toString('base64');
97
+ const dataUrl = `data:text/javascript;base64,${base64Code}`;
98
+ compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', ()=>{
99
+ new compiler.webpack.EntryPlugin(compiler.context, dataUrl, {
100
+ name: name
101
+ }).apply(compiler);
102
+ });
103
+ }
104
+ apply(compiler) {
105
+ const { name, getPublicPath } = this._options;
106
+ if (!getPublicPath || !name) {
107
+ return;
108
+ }
109
+ const containerManager = new managers_namespaceObject.ContainerManager();
110
+ containerManager.init(this._options);
111
+ if (!containerManager.enable) {
112
+ external_logger_js_default().warn("Detect you don't set exposes, 'getPublicPath' will not have effect.");
113
+ return;
114
+ }
115
+ RemoteEntryPlugin.addPublicPathEntry(compiler, getPublicPath, name);
116
+ }
117
+ constructor(options){
118
+ this.name = 'VmokRemoteEntryPlugin';
119
+ this._options = options;
120
+ }
121
+ }
122
+
123
+ exports.RemoteEntryPlugin = __webpack_exports__.RemoteEntryPlugin;
124
+ for(var __rspack_i in __webpack_exports__) {
125
+ if(["RemoteEntryPlugin"].indexOf(__rspack_i) === -1) {
126
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
127
+ }
128
+ }
129
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,12 +1,9 @@
1
- import pBtoa from 'btoa';
2
- import { ContainerManager } from '@module-federation/managers';
3
- import { createInfrastructureLogger, createLogger } from '@module-federation/sdk';
1
+ import { ContainerManager } from "@module-federation/managers";
2
+ import logger from "./logger.mjs";
3
+
4
+
5
+
4
6
 
5
- const isLoggerFactory = (candidate) => typeof candidate === 'function';
6
- const createBundlerLogger = isLoggerFactory(createInfrastructureLogger)
7
- ? (prefix) => createInfrastructureLogger(prefix)
8
- : createLogger;
9
- const logger = createBundlerLogger('[ Module Federation Rspack Plugin ]');
10
7
 
11
8
  // @ts-ignore
12
9
  const charMap = {
@@ -21,30 +18,25 @@ const charMap = {
21
18
  '\t': '\\t',
22
19
  '\0': '\\0',
23
20
  '\u2028': '\\u2028',
24
- '\u2029': '\\u2029',
21
+ '\u2029': '\\u2029'
25
22
  };
26
23
  function escapeUnsafeChars(str) {
27
- return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x) => charMap[x]);
24
+ return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x)=>charMap[x]);
28
25
  }
29
26
  class RemoteEntryPlugin {
30
- constructor(options) {
31
- this.name = 'VmokRemoteEntryPlugin';
32
- this._options = options;
33
- }
34
27
  static addPublicPathEntry(compiler, getPublicPath, name) {
35
28
  let code;
36
29
  const sanitizedPublicPath = escapeUnsafeChars(getPublicPath);
37
30
  if (!getPublicPath.startsWith('function')) {
38
31
  code = `${compiler.webpack.RuntimeGlobals.publicPath} = new Function(${JSON.stringify(sanitizedPublicPath)})()`;
39
- }
40
- else {
32
+ } else {
41
33
  code = `(${sanitizedPublicPath}())`;
42
34
  }
43
- const base64Code = pBtoa(code);
35
+ const base64Code = Buffer.from(code, 'utf8').toString('base64');
44
36
  const dataUrl = `data:text/javascript;base64,${base64Code}`;
45
- compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', () => {
37
+ compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', ()=>{
46
38
  new compiler.webpack.EntryPlugin(compiler.context, dataUrl, {
47
- name: name,
39
+ name: name
48
40
  }).apply(compiler);
49
41
  });
50
42
  }
@@ -61,7 +53,10 @@ class RemoteEntryPlugin {
61
53
  }
62
54
  RemoteEntryPlugin.addPublicPathEntry(compiler, getPublicPath, name);
63
55
  }
56
+ constructor(options){
57
+ this.name = 'VmokRemoteEntryPlugin';
58
+ this._options = options;
59
+ }
64
60
  }
65
61
 
66
- export { RemoteEntryPlugin as R, logger as l };
67
- //# sourceMappingURL=RemoteEntryPlugin.esm.mjs.map
62
+ export { RemoteEntryPlugin };
@@ -0,0 +1,13 @@
1
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
3
+ export declare const PLUGIN_NAME = "RspackTreeShakingSharedPlugin";
4
+ export interface TreeShakingSharedPluginOptions {
5
+ mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
6
+ secondary?: boolean;
7
+ }
8
+ export declare class TreeShakingSharedPlugin implements RspackPluginInstance {
9
+ readonly name = "RspackTreeShakingSharedPlugin";
10
+ private _options;
11
+ constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
12
+ apply(compiler: Compiler): void;
13
+ }
@@ -0,0 +1,67 @@
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/define_property_getters
13
+ (() => {
14
+ __webpack_require__.d = (exports, getters, values) => {
15
+ var define = (defs, kind) => {
16
+ for(var key in defs) {
17
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
18
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
19
+ }
20
+ }
21
+ };
22
+ define(getters, "get");
23
+ define(values, "value");
24
+ };
25
+ })();
26
+ // webpack/runtime/has_own_property
27
+ (() => {
28
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
29
+ })();
30
+ // webpack/runtime/make_namespace_object
31
+ (() => {
32
+ // define __esModule on exports
33
+ __webpack_require__.r = (exports) => {
34
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
35
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
+ }
37
+ Object.defineProperty(exports, '__esModule', { value: true });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ __webpack_require__.r(__webpack_exports__);
42
+ const PLUGIN_NAME = 'RspackTreeShakingSharedPlugin';
43
+ class TreeShakingSharedPlugin {
44
+ apply(compiler) {
45
+ // @ts-expect-error wait rspack release
46
+ new compiler.rspack.sharing.TreeShakingSharedPlugin(this._options).apply(compiler);
47
+ }
48
+ constructor(options){
49
+ this.name = PLUGIN_NAME;
50
+ this._options = options;
51
+ }
52
+ }
53
+
54
+ __webpack_require__.d(__webpack_exports__, {
55
+ TreeShakingSharedPlugin: () => (TreeShakingSharedPlugin)
56
+ }, {
57
+ PLUGIN_NAME: PLUGIN_NAME
58
+ });
59
+
60
+ exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
61
+ exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
62
+ for(var __rspack_i in __webpack_exports__) {
63
+ if(["PLUGIN_NAME","TreeShakingSharedPlugin"].indexOf(__rspack_i) === -1) {
64
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
65
+ }
66
+ }
67
+ Object.defineProperty(exports, '__esModule', { value: true });