@module-federation/rsbuild-plugin 2.0.0 → 2.1.0

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
@@ -11,7 +11,8 @@ npm install @module-federation/enhanced
11
11
  ```
12
12
 
13
13
  ### Rsbuild App
14
- ``` js
14
+
15
+ ```js
15
16
  import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
16
17
  import { defineConfig } from '@rsbuild/core';
17
18
  import { pluginReact } from '@rsbuild/plugin-react';
@@ -33,8 +34,56 @@ export default defineConfig({
33
34
  });
34
35
  ```
35
36
 
37
+ ### Rsbuild App SSR (Node target with custom environment)
38
+
39
+ Use `target: 'node'` with an explicit `environment` to apply federation to a
40
+ specific Rsbuild app environment (for example `ssr`).
41
+
42
+ ```ts
43
+ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
44
+ import { defineConfig } from '@rsbuild/core';
45
+
46
+ export default defineConfig({
47
+ environments: {
48
+ client: {},
49
+ ssr: {},
50
+ },
51
+ plugins: [
52
+ pluginModuleFederation(
53
+ {
54
+ name: 'host',
55
+ remotes: {
56
+ remote: 'remote@http://localhost:3001/mf-manifest.json',
57
+ },
58
+ },
59
+ {
60
+ target: 'node',
61
+ environment: 'ssr',
62
+ },
63
+ ),
64
+ ],
65
+ });
66
+ ```
67
+
68
+ `target: 'dual'` support remains scoped to Rslib/Rspress workflows.
69
+
70
+ ### Default environment detection
71
+
72
+ If `environment` is omitted, the plugin will choose a default per tool:
73
+
74
+ - **Rslib**: `mf`
75
+ - **Rsbuild app**:
76
+ - `target: 'web'` → `web`
77
+ - `target: 'node'` → `node`
78
+ - **Rspress**:
79
+ - `target: 'web'` → `web`
80
+ - `target: 'node'` → `node`
81
+
82
+ You can still override with `environment` when your project uses custom names.
83
+
36
84
  ### Rslib Module
37
- ``` js
85
+
86
+ ```js
38
87
  import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
39
88
  import { defineConfig } from '@rslib/core';
40
89
 
@@ -70,3 +119,7 @@ export default defineConfig({
70
119
  ],
71
120
  });
72
121
  ```
122
+
123
+ ## Documentation
124
+
125
+ See [https://module-federation.io/guide/build-plugins/plugins-rsbuild.html](https://module-federation.io/guide/build-plugins/plugins-rsbuild.html) fordetails.
@@ -27,7 +27,7 @@ declare const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = "rsbuild:module-federation
27
27
  export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, SSR_DIR };
28
28
  export declare function isMFFormat(bundlerConfig: Rspack.Configuration): boolean;
29
29
  declare const isSSRConfig: (bundlerConfigName?: string) => boolean;
30
- declare const isRspressSSGConfig: (bundlerConfigName?: string) => bundlerConfigName is "node";
30
+ declare const isRspressSSGConfig: (bundlerConfigName?: string) => boolean;
31
31
  export declare const pluginModuleFederation: (moduleFederationOptions: ModuleFederationOptions, rsbuildOptions?: RSBUILD_PLUGIN_OPTIONS) => RsbuildPlugin;
32
32
  export { createModuleFederationConfig } from '@module-federation/sdk';
33
33
  export { TreeShakingSharedPlugin };
@@ -0,0 +1,475 @@
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
+ /************************************************************************/
13
+ // webpack/runtime/compat_get_default_export
14
+ (() => {
15
+ // getDefaultExport function for compatibility with non-ESM modules
16
+ __webpack_require__.n = (module) => {
17
+ var getter = module && module.__esModule ?
18
+ () => (module['default']) :
19
+ () => (module);
20
+ __webpack_require__.d(getter, { a: getter });
21
+ return getter;
22
+ };
23
+
24
+ })();
25
+ // webpack/runtime/define_property_getters
26
+ (() => {
27
+ __webpack_require__.d = (exports, definition) => {
28
+ for(var key in definition) {
29
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ })();
35
+ // webpack/runtime/has_own_property
36
+ (() => {
37
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
38
+ })();
39
+ // webpack/runtime/make_namespace_object
40
+ (() => {
41
+ // define __esModule on exports
42
+ __webpack_require__.r = (exports) => {
43
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
44
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45
+ }
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ };
48
+ })();
49
+ /************************************************************************/
50
+ var __webpack_exports__ = {};
51
+ // ESM COMPAT FLAG
52
+ __webpack_require__.r(__webpack_exports__);
53
+
54
+ // EXPORTS
55
+ __webpack_require__.d(__webpack_exports__, {
56
+ pluginModuleFederation: () => (/* binding */ pluginModuleFederation),
57
+ RSBUILD_PLUGIN_MODULE_FEDERATION_NAME: () => (/* binding */ RSBUILD_PLUGIN_MODULE_FEDERATION_NAME),
58
+ PLUGIN_NAME: () => (/* reexport */ rspack_namespaceObject.PLUGIN_NAME),
59
+ SSR_DIR: () => (/* reexport */ external_utils_js_namespaceObject.SSR_DIR),
60
+ isMFFormat: () => (/* binding */ isMFFormat),
61
+ TreeShakingSharedPlugin: () => (/* reexport */ rspack_namespaceObject.TreeShakingSharedPlugin),
62
+ createModuleFederationConfig: () => (/* reexport */ sdk_namespaceObject.createModuleFederationConfig)
63
+ });
64
+
65
+ ;// CONCATENATED MODULE: external "@module-federation/enhanced"
66
+ const enhanced_namespaceObject = require("@module-federation/enhanced");
67
+ ;// CONCATENATED MODULE: external "@module-federation/enhanced/rspack"
68
+ const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
69
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
70
+ const sdk_namespaceObject = require("@module-federation/sdk");
71
+ ;// CONCATENATED MODULE: external "../../package.json"
72
+ const external_package_json_namespaceObject = require("../../package.json");
73
+ var external_package_json_default = /*#__PURE__*/__webpack_require__.n(external_package_json_namespaceObject);
74
+ ;// CONCATENATED MODULE: external "../logger.js"
75
+ const external_logger_js_namespaceObject = require("../logger.js");
76
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
77
+ ;// CONCATENATED MODULE: external "../utils.js"
78
+ const external_utils_js_namespaceObject = require("../utils.js");
79
+ ;// CONCATENATED MODULE: external "../constant.js"
80
+ const external_constant_js_namespaceObject = require("../constant.js");
81
+ ;// CONCATENATED MODULE: external "../utils/ssr.js"
82
+ const ssr_js_namespaceObject = require("../utils/ssr.js");
83
+ ;// CONCATENATED MODULE: ./src/cli/index.ts
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+ const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
93
+ const RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
94
+
95
+ const LIB_FORMAT = [
96
+ 'umd',
97
+ 'modern-module'
98
+ ];
99
+ const DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
100
+ const DEFAULT_WEB_ENVIRONMENT_NAME = 'web';
101
+ const DEFAULT_NODE_ENVIRONMENT_NAME = 'node';
102
+ const resolveDefaultEnvironmentName = ({ callerName, target })=>{
103
+ if (callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSLIB) {
104
+ return DEFAULT_MF_ENVIRONMENT_NAME;
105
+ }
106
+ if (callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSPRESS) {
107
+ if (target === 'node') {
108
+ return DEFAULT_NODE_ENVIRONMENT_NAME;
109
+ }
110
+ return DEFAULT_WEB_ENVIRONMENT_NAME;
111
+ }
112
+ if (target === 'node') {
113
+ return DEFAULT_NODE_ENVIRONMENT_NAME;
114
+ }
115
+ return DEFAULT_WEB_ENVIRONMENT_NAME;
116
+ };
117
+ function isStoryBook(rsbuildConfig) {
118
+ var _rsbuildConfig_plugins;
119
+ if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find((p)=>p && 'name' in p && p.name === 'module-federation-storybook-plugin')) {
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+ function isMFFormat(bundlerConfig) {
125
+ var _bundlerConfig_output;
126
+ const library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
127
+ if (bundlerConfig.name === external_utils_js_namespaceObject.SSR_ENV_NAME) {
128
+ return true;
129
+ }
130
+ return !(typeof library === 'object' && !Array.isArray(library) && 'type' in library && // if the type is umd/modern-module or commonjs*, means this is a normal library , not mf
131
+ (LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
132
+ }
133
+ const isSSRConfig = (bundlerConfigName)=>Boolean(bundlerConfigName === external_utils_js_namespaceObject.SSR_ENV_NAME);
134
+ const isRspressSSGConfig = (bundlerConfigName)=>{
135
+ return [
136
+ external_constant_js_namespaceObject.RSPRESS_BUNDLER_CONFIG_NAME,
137
+ external_constant_js_namespaceObject.RSPRESS_SSG_MD_ENV_NAME
138
+ ].includes(bundlerConfigName || '');
139
+ };
140
+ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
141
+ name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
142
+ setup: (api)=>{
143
+ if (!(moduleFederationOptions === null || moduleFederationOptions === void 0 ? void 0 : moduleFederationOptions.name)) {
144
+ throw new Error('The module federation option "name" is required in @module-federation/rsbuild-plugin.');
145
+ }
146
+ const { target = 'web', ssr = undefined, ssrDir = external_utils_js_namespaceObject.SSR_DIR, environment: configuredEnvironment } = rsbuildOptions || {};
147
+ if (ssr) {
148
+ throw new Error("The `ssr` option is deprecated. If you want to enable SSR, please use `target: 'dual'` instead.");
149
+ }
150
+ const { callerName } = api.context;
151
+ const originalRsbuildConfig = api.getRsbuildConfig();
152
+ if (!callerName) {
153
+ throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
154
+ }
155
+ const isRslib = callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSLIB;
156
+ const isRspress = callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSPRESS;
157
+ const isSSR = target === 'dual';
158
+ const environment = configuredEnvironment ?? resolveDefaultEnvironmentName({
159
+ callerName,
160
+ target
161
+ });
162
+ if (isSSR && !isStoryBook(originalRsbuildConfig)) {
163
+ var _rsbuildConfig_environments;
164
+ if (!isRslib && !isRspress) {
165
+ throw new Error(`'target' option is only supported in Rslib.`);
166
+ }
167
+ const rsbuildConfig = api.getRsbuildConfig();
168
+ if (!isRspress && (!((_rsbuildConfig_environments = rsbuildConfig.environments) === null || _rsbuildConfig_environments === void 0 ? void 0 : _rsbuildConfig_environments[environment]) || Object.keys(rsbuildConfig.environments).some((key)=>key.startsWith(environment) && key !== environment))) {
169
+ throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
170
+ }
171
+ (0,external_utils_js_namespaceObject.setSSREnv)();
172
+ }
173
+ const sharedOptions = (0,enhanced_namespaceObject.parseOptions)(moduleFederationOptions.shared || [], (item, key)=>{
174
+ if (typeof item !== 'string') throw new Error('Unexpected array in shared');
175
+ const config = item === key || !(0,sdk_namespaceObject.isRequiredVersion)(item) ? {
176
+ import: item
177
+ } : {
178
+ import: key,
179
+ requiredVersion: item
180
+ };
181
+ return config;
182
+ }, (item)=>item);
183
+ // shared[0] is the shared name
184
+ const shared = sharedOptions.map((shared)=>shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0]);
185
+ api.modifyRsbuildConfig((config)=>{
186
+ // skip storybook
187
+ if (isStoryBook(config)) {
188
+ return;
189
+ }
190
+ // Change some default configs for remote modules
191
+ if (moduleFederationOptions.exposes) {
192
+ var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
193
+ config.dev ||= {};
194
+ config.server ||= {};
195
+ const userConfig = api.getRsbuildConfig('original');
196
+ // Allow remote modules to be loaded by setting CORS headers
197
+ // This is required for MF to work properly across different origins
198
+ config.server.headers ||= {};
199
+ if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof ((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.cors) === 'object' && userConfig.server.cors.origin)) {
200
+ const corsWarnMsgs = [
201
+ 'Detect that CORS options are not set, mf Rsbuild plugin will add default cors header: server.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins in "server.cors" instead.',
202
+ 'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
203
+ ];
204
+ !isRslib && !isRspress && external_logger_js_default().warn(corsWarnMsgs.join('\n'));
205
+ config.server.headers['Access-Control-Allow-Origin'] = '*';
206
+ }
207
+ // For remote modules, Rsbuild should send the ws request to the provider's dev server.
208
+ // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
209
+ if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
210
+ config.dev.client ||= {};
211
+ config.dev.client.port = config.server.port;
212
+ }
213
+ // Change the default assetPrefix to `true` for remote modules.
214
+ // This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
215
+ const originalConfig = api.getRsbuildConfig('original');
216
+ if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.base)) {
217
+ config.dev.assetPrefix = true;
218
+ }
219
+ }
220
+ if (isSSR) {
221
+ var _config_environments, _config_environments1;
222
+ if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[external_utils_js_namespaceObject.SSR_ENV_NAME]) {
223
+ throw new Error(`'${external_utils_js_namespaceObject.SSR_ENV_NAME}' environment is already defined.Please use another name.`);
224
+ }
225
+ config.environments[external_utils_js_namespaceObject.SSR_ENV_NAME] = (0,external_utils_js_namespaceObject.createSSRREnvConfig)((_config_environments1 = config.environments) === null || _config_environments1 === void 0 ? void 0 : _config_environments1[environment], moduleFederationOptions, ssrDir, config, callerName);
226
+ const ssgMDEnv = config.environments[external_constant_js_namespaceObject.RSPRESS_SSG_MD_ENV_NAME];
227
+ if (isRspress && ssgMDEnv) {
228
+ (0,ssr_js_namespaceObject.patchToolsTspack)(ssgMDEnv, (config, { environment })=>{
229
+ config.target = 'async-node';
230
+ });
231
+ }
232
+ } else if (target === 'node') {
233
+ var _config_environments2;
234
+ const nodeTargetEnv = (_config_environments2 = config.environments) === null || _config_environments2 === void 0 ? void 0 : _config_environments2[environment];
235
+ if (!nodeTargetEnv) {
236
+ const availableEnvironments = Object.keys(config.environments || {});
237
+ const availableEnvironmentsLabel = availableEnvironments.length > 0 ? availableEnvironments.join(', ') : '(none)';
238
+ throw new Error(`Can not find environment '${environment}' when using target: 'node'. Available environments: ${availableEnvironmentsLabel}.`);
239
+ }
240
+ (0,ssr_js_namespaceObject.patchToolsTspack)(nodeTargetEnv, (config, { environment })=>{
241
+ config.target = 'async-node';
242
+ });
243
+ }
244
+ });
245
+ api.modifyEnvironmentConfig((config)=>{
246
+ // Module Federation runtime uses ES6+ syntax,
247
+ // adding to include and let SWC transform it
248
+ config.source.include = [
249
+ ...config.source.include || [],
250
+ /@module-federation[\\/]/
251
+ ];
252
+ return config;
253
+ });
254
+ const generateMergedStatsAndManifestOptions = {
255
+ options: {
256
+ nodePlugin: undefined,
257
+ browserPlugin: undefined,
258
+ rspressSSGPlugin: undefined,
259
+ distOutputDir: undefined,
260
+ browserEnvironmentName: undefined,
261
+ nodeEnvironmentName: undefined
262
+ },
263
+ assetResources: {},
264
+ isSSRConfig,
265
+ isRspressSSGConfig
266
+ };
267
+ api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
268
+ const defaultBrowserEnvironmentName = environment;
269
+ const assetFileNames = (0,sdk_namespaceObject.getManifestFileName)(moduleFederationOptions.manifest);
270
+ if (moduleFederationOptions.manifest !== false) {
271
+ api.processAssets({
272
+ stage: 'report'
273
+ }, ({ assets, environment: envContext })=>{
274
+ const expectedBrowserEnv = generateMergedStatsAndManifestOptions.options.browserEnvironmentName ?? defaultBrowserEnvironmentName;
275
+ const expectedNodeEnv = generateMergedStatsAndManifestOptions.options.nodeEnvironmentName ?? external_utils_js_namespaceObject.SSR_ENV_NAME;
276
+ const envName = envContext.name;
277
+ if (envName !== expectedBrowserEnv && envName !== expectedNodeEnv) {
278
+ return;
279
+ }
280
+ const assetResources = generateMergedStatsAndManifestOptions.assetResources;
281
+ const targetResources = assetResources[envName] || (assetResources[envName] = {});
282
+ const statsAsset = assets[assetFileNames.statsFileName];
283
+ if (statsAsset) {
284
+ try {
285
+ const raw = statsAsset.source();
286
+ const content = typeof raw === 'string' ? raw : raw.toString();
287
+ targetResources.stats = {
288
+ data: JSON.parse(content),
289
+ filename: assetFileNames.statsFileName
290
+ };
291
+ } catch (err) {
292
+ const message = err instanceof Error ? err.message : String(err);
293
+ external_logger_js_default().error(`Failed to parse stats asset "${assetFileNames.statsFileName}" for environment "${envName}": ${message} `);
294
+ }
295
+ }
296
+ const manifestAsset = assets[assetFileNames.manifestFileName];
297
+ if (manifestAsset) {
298
+ try {
299
+ const raw = manifestAsset.source();
300
+ const content = typeof raw === 'string' ? raw : raw.toString();
301
+ targetResources.manifest = {
302
+ data: JSON.parse(content),
303
+ filename: assetFileNames.manifestFileName
304
+ };
305
+ } catch (err) {
306
+ const message = err instanceof Error ? err.message : String(err);
307
+ external_logger_js_default().error(`Failed to parse manifest asset "${assetFileNames.manifestFileName}" for environment "${envName}": ${message} `);
308
+ }
309
+ }
310
+ });
311
+ }
312
+ api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
313
+ if (!bundlerConfigs) {
314
+ throw new Error('Can not get bundlerConfigs!');
315
+ }
316
+ bundlerConfigs.forEach((bundlerConfig)=>{
317
+ const bundlerConfigName = bundlerConfig.name || '';
318
+ const isConfiguredEnvironmentConfig = bundlerConfigName === environment;
319
+ const isNodeTargetEnvironmentConfig = target === 'node' && bundlerConfigName === environment;
320
+ const isRspressSSGEnvironmentConfig = isRspressSSGConfig(bundlerConfig.name);
321
+ const isActiveRspressSSGEnvironmentConfig = isRspress && isRspressSSGEnvironmentConfig;
322
+ const shouldUseSSRPluginConfig = isSSRConfig(bundlerConfig.name) || isNodeTargetEnvironmentConfig;
323
+ if (target === 'node' && !isNodeTargetEnvironmentConfig && !isActiveRspressSSGEnvironmentConfig) {
324
+ return;
325
+ }
326
+ // For non-node targets, scope each plugin instance to its configured
327
+ // environment plus explicit SSR/SSG environments. This prevents a
328
+ // browser-targeted instance from mutating SSR configs.
329
+ if (target !== 'node' && !isConfiguredEnvironmentConfig && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
330
+ return;
331
+ }
332
+ if (!isMFFormat(bundlerConfig) && !isRspress && !isNodeTargetEnvironmentConfig) {
333
+ return;
334
+ } else if (isStoryBook(originalRsbuildConfig)) {
335
+ bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
336
+ } else {
337
+ var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1, _bundlerConfig_output2;
338
+ // mf
339
+ (0,external_utils_js_namespaceObject.autoDeleteSplitChunkCacheGroups)(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
340
+ (0,external_utils_js_namespaceObject.addDataFetchExposes)(moduleFederationOptions.exposes, shouldUseSSRPluginConfig);
341
+ const ssrModuleFederationOptions = shouldUseSSRPluginConfig ? (0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions) : undefined;
342
+ (_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? true : delete _bundlerConfig_optimization1.runtimeChunk;
343
+ const externals = bundlerConfig.externals;
344
+ if (Array.isArray(externals)) {
345
+ const sharedModules = new Set();
346
+ bundlerConfig.externals = externals.filter((ext)=>{
347
+ let sharedModule;
348
+ if ((0,external_utils_js_namespaceObject.isRegExp)(ext)) {
349
+ const match = shared.some((dep)=>{
350
+ if (ext.test(dep) || ext.test((external_package_json_default()).name)) {
351
+ sharedModule = dep;
352
+ return true;
353
+ }
354
+ return false;
355
+ });
356
+ match && sharedModule && sharedModules.add(sharedModule);
357
+ return !match;
358
+ }
359
+ if (typeof ext === 'string') {
360
+ if (ext === (external_package_json_default()).name) {
361
+ return false;
362
+ }
363
+ const match = shared.some((dep)=>{
364
+ if (dep === ext) {
365
+ sharedModule = dep;
366
+ }
367
+ return dep === ext;
368
+ });
369
+ if (match) {
370
+ sharedModule && sharedModules.add(sharedModule);
371
+ return false;
372
+ }
373
+ return true;
374
+ }
375
+ return true;
376
+ });
377
+ if (sharedModules.size > 0) {
378
+ for (const sharedModule of sharedModules){
379
+ external_logger_js_default().log(`${sharedModule} is removed from externals because it is a shared module.`);
380
+ }
381
+ }
382
+ }
383
+ if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig && target !== 'node') {
384
+ bundlerConfig.output.chunkLoading = 'jsonp';
385
+ bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name} `;
386
+ }
387
+ if (isNodeTargetEnvironmentConfig) {
388
+ (0,ssr_js_namespaceObject.patchNodeConfig)(bundlerConfig, ssrModuleFederationOptions ?? moduleFederationOptions);
389
+ }
390
+ // `uniqueName` is required for react refresh to work
391
+ if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
392
+ bundlerConfig.output.uniqueName = moduleFederationOptions.name;
393
+ }
394
+ // Set default publicPath to 'auto' if not explicitly configured
395
+ // This allows remote chunks to load from the same origin as the remote application's manifest
396
+ if (((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.publicPath) === undefined && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
397
+ bundlerConfig.output.publicPath = 'auto';
398
+ }
399
+ if (!bundlerConfig.plugins.find((p)=>p && p.name === rspack_namespaceObject.PLUGIN_NAME)) {
400
+ var _bundlerConfig_output3;
401
+ if (shouldUseSSRPluginConfig) {
402
+ const ssrMFConfig = ssrModuleFederationOptions ?? (0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions);
403
+ generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack_namespaceObject.ModuleFederationPlugin(ssrMFConfig);
404
+ generateMergedStatsAndManifestOptions.options.nodeEnvironmentName = bundlerConfig.name || external_utils_js_namespaceObject.SSR_ENV_NAME;
405
+ bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
406
+ return;
407
+ } else if (isActiveRspressSSGEnvironmentConfig) {
408
+ const mfConfig = {
409
+ ...(0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions),
410
+ // expose in mf-ssg env
411
+ exposes: {},
412
+ manifest: false,
413
+ library: undefined
414
+ };
415
+ (0,external_utils_js_namespaceObject.patchSSRRspackConfig)(bundlerConfig, mfConfig, external_constant_js_namespaceObject.RSPRESS_SSR_DIR, callerName, false, false);
416
+ bundlerConfig.output ||= {};
417
+ bundlerConfig.output.publicPath = '/';
418
+ // MF depend on asyncChunks
419
+ bundlerConfig.output.asyncChunks = undefined;
420
+ const p = new rspack_namespaceObject.ModuleFederationPlugin(mfConfig);
421
+ if (bundlerConfig.name === external_constant_js_namespaceObject.RSPRESS_BUNDLER_CONFIG_NAME) {
422
+ generateMergedStatsAndManifestOptions.options.rspressSSGPlugin = p;
423
+ }
424
+ bundlerConfig.plugins.push(p);
425
+ return;
426
+ }
427
+ generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack_namespaceObject.ModuleFederationPlugin(moduleFederationOptions);
428
+ generateMergedStatsAndManifestOptions.options.distOutputDir = ((_bundlerConfig_output3 = bundlerConfig.output) === null || _bundlerConfig_output3 === void 0 ? void 0 : _bundlerConfig_output3.path) || '';
429
+ generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
430
+ bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
431
+ }
432
+ }
433
+ });
434
+ });
435
+ const generateMergedStatsAndManifest = ()=>{
436
+ const { distOutputDir, browserEnvironmentName, nodeEnvironmentName } = generateMergedStatsAndManifestOptions.options;
437
+ if (!distOutputDir || !browserEnvironmentName || !nodeEnvironmentName) {
438
+ return;
439
+ }
440
+ const assetResources = generateMergedStatsAndManifestOptions.assetResources;
441
+ const browserAssets = assetResources[browserEnvironmentName];
442
+ const nodeAssets = assetResources[nodeEnvironmentName];
443
+ if (!browserAssets || !nodeAssets) {
444
+ return;
445
+ }
446
+ try {
447
+ (0,external_utils_js_namespaceObject.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
448
+ } catch (err) {
449
+ external_logger_js_default().error(err);
450
+ }
451
+ };
452
+ api.onDevCompileDone(()=>{
453
+ generateMergedStatsAndManifest();
454
+ });
455
+ api.onAfterBuild(()=>{
456
+ generateMergedStatsAndManifest();
457
+ });
458
+ }
459
+ });
460
+
461
+
462
+
463
+ exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
464
+ exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = __webpack_exports__.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
465
+ exports.SSR_DIR = __webpack_exports__.SSR_DIR;
466
+ exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
467
+ exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
468
+ exports.isMFFormat = __webpack_exports__.isMFFormat;
469
+ exports.pluginModuleFederation = __webpack_exports__.pluginModuleFederation;
470
+ for(var __webpack_i__ in __webpack_exports__) {
471
+ if(["PLUGIN_NAME","RSBUILD_PLUGIN_MODULE_FEDERATION_NAME","SSR_DIR","TreeShakingSharedPlugin","createModuleFederationConfig","isMFFormat","pluginModuleFederation"].indexOf(__webpack_i__) === -1) {
472
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
473
+ }
474
+ }
475
+ Object.defineProperty(exports, '__esModule', { value: true });