@module-federation/rsbuild-plugin 2.5.1 → 2.7.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/dist/cli/index.js +34 -40
- package/dist/cli/index.mjs +19 -35
- package/dist/constant.js +24 -20
- package/dist/constant.mjs +0 -2
- package/dist/index.js +19 -18
- package/dist/index.mjs +1 -2
- package/dist/logger.js +14 -12
- package/dist/logger.mjs +2 -4
- package/dist/utils/addDataFetchExposes.js +13 -11
- package/dist/utils/addDataFetchExposes.mjs +0 -5
- package/dist/utils/autoDeleteSplitChunkCacheGroups.js +18 -15
- package/dist/utils/autoDeleteSplitChunkCacheGroups.mjs +1 -3
- package/dist/utils/index.js +19 -17
- package/dist/utils/index.mjs +6 -13
- package/dist/utils/manifest.js +13 -11
- package/dist/utils/manifest.mjs +0 -3
- package/dist/utils/ssr.js +36 -45
- package/dist/utils/ssr.mjs +16 -32
- package/dist/utils.js +19 -18
- package/dist/utils.mjs +1 -2
- package/package.json +9 -8
package/dist/cli/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
|
9
9
|
// The require scope
|
|
10
10
|
var __webpack_require__ = {};
|
|
11
11
|
|
|
12
|
-
/************************************************************************/
|
|
13
12
|
// webpack/runtime/compat_get_default_export
|
|
14
13
|
(() => {
|
|
15
14
|
// getDefaultExport function for compatibility with non-ESM modules
|
|
@@ -24,12 +23,16 @@ __webpack_require__.n = (module) => {
|
|
|
24
23
|
})();
|
|
25
24
|
// webpack/runtime/define_property_getters
|
|
26
25
|
(() => {
|
|
27
|
-
__webpack_require__.d = (exports,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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");
|
|
33
36
|
};
|
|
34
37
|
})();
|
|
35
38
|
// webpack/runtime/has_own_property
|
|
@@ -46,20 +49,19 @@ __webpack_require__.r = (exports) => {
|
|
|
46
49
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
50
|
};
|
|
48
51
|
})();
|
|
49
|
-
/************************************************************************/
|
|
50
52
|
var __webpack_exports__ = {};
|
|
51
53
|
// ESM COMPAT FLAG
|
|
52
54
|
__webpack_require__.r(__webpack_exports__);
|
|
53
55
|
|
|
54
56
|
// EXPORTS
|
|
55
57
|
__webpack_require__.d(__webpack_exports__, {
|
|
56
|
-
pluginModuleFederation: () => (/* binding */ pluginModuleFederation),
|
|
57
|
-
RSBUILD_PLUGIN_MODULE_FEDERATION_NAME: () => (/* binding */ RSBUILD_PLUGIN_MODULE_FEDERATION_NAME),
|
|
58
58
|
PLUGIN_NAME: () => (/* reexport */ rspack_namespaceObject.PLUGIN_NAME),
|
|
59
|
+
RSBUILD_PLUGIN_MODULE_FEDERATION_NAME: () => (/* binding */ RSBUILD_PLUGIN_MODULE_FEDERATION_NAME),
|
|
59
60
|
SSR_DIR: () => (/* reexport */ external_utils_js_namespaceObject.SSR_DIR),
|
|
60
|
-
isMFFormat: () => (/* binding */ isMFFormat),
|
|
61
61
|
TreeShakingSharedPlugin: () => (/* reexport */ rspack_namespaceObject.TreeShakingSharedPlugin),
|
|
62
|
-
createModuleFederationConfig: () => (/* reexport */ sdk_namespaceObject.createModuleFederationConfig)
|
|
62
|
+
createModuleFederationConfig: () => (/* reexport */ sdk_namespaceObject.createModuleFederationConfig),
|
|
63
|
+
isMFFormat: () => (/* binding */ isMFFormat),
|
|
64
|
+
pluginModuleFederation: () => (/* binding */ pluginModuleFederation)
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
;// CONCATENATED MODULE: external "@module-federation/enhanced"
|
|
@@ -111,15 +113,13 @@ const resolveDefaultEnvironmentName = ({ callerName, target })=>{
|
|
|
111
113
|
return DEFAULT_WEB_ENVIRONMENT_NAME;
|
|
112
114
|
};
|
|
113
115
|
function isStoryBook(rsbuildConfig) {
|
|
114
|
-
|
|
115
|
-
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')) {
|
|
116
|
+
if (rsbuildConfig.plugins?.find((p)=>p && 'name' in p && p.name === 'module-federation-storybook-plugin')) {
|
|
116
117
|
return true;
|
|
117
118
|
}
|
|
118
119
|
return false;
|
|
119
120
|
}
|
|
120
121
|
function isMFFormat(bundlerConfig) {
|
|
121
|
-
|
|
122
|
-
const library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
122
|
+
const library = bundlerConfig.output?.library;
|
|
123
123
|
if (bundlerConfig.name === external_utils_js_namespaceObject.SSR_ENV_NAME) {
|
|
124
124
|
return true;
|
|
125
125
|
}
|
|
@@ -136,7 +136,7 @@ const isRspressSSGConfig = (bundlerConfigName)=>{
|
|
|
136
136
|
const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
137
137
|
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
138
138
|
setup: (api)=>{
|
|
139
|
-
if (!
|
|
139
|
+
if (!moduleFederationOptions?.name) {
|
|
140
140
|
throw new Error('The module federation option "name" is required in @module-federation/rsbuild-plugin.');
|
|
141
141
|
}
|
|
142
142
|
const { target = 'web', ssr = undefined, ssrDir = external_utils_js_namespaceObject.SSR_DIR, environment: configuredEnvironment } = rsbuildOptions || {};
|
|
@@ -156,12 +156,11 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
156
156
|
target
|
|
157
157
|
});
|
|
158
158
|
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
159
|
-
var _rsbuildConfig_environments;
|
|
160
159
|
if (!isRslib && !isRspress) {
|
|
161
160
|
throw new Error(`'target' option is only supported in Rslib.`);
|
|
162
161
|
}
|
|
163
162
|
const rsbuildConfig = api.getRsbuildConfig();
|
|
164
|
-
if (!isRspress && (!
|
|
163
|
+
if (!isRspress && (!rsbuildConfig.environments?.[environment] || Object.keys(rsbuildConfig.environments).some((key)=>key.startsWith(environment) && key !== environment))) {
|
|
165
164
|
throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
|
|
166
165
|
}
|
|
167
166
|
(0,external_utils_js_namespaceObject.setSSREnv)();
|
|
@@ -185,14 +184,13 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
185
184
|
}
|
|
186
185
|
// Change some default configs for remote modules
|
|
187
186
|
if (moduleFederationOptions.exposes) {
|
|
188
|
-
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
189
187
|
config.dev ||= {};
|
|
190
188
|
config.server ||= {};
|
|
191
189
|
const userConfig = api.getRsbuildConfig('original');
|
|
192
190
|
// Allow remote modules to be loaded by setting CORS headers
|
|
193
191
|
// This is required for MF to work properly across different origins
|
|
194
192
|
config.server.headers ||= {};
|
|
195
|
-
if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof
|
|
193
|
+
if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof userConfig.server?.cors === 'object' && userConfig.server.cors.origin)) {
|
|
196
194
|
const corsWarnMsgs = [
|
|
197
195
|
'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.',
|
|
198
196
|
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
@@ -202,23 +200,22 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
202
200
|
}
|
|
203
201
|
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
204
202
|
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
205
|
-
if (
|
|
203
|
+
if (config.server?.port && !config.dev.client?.port) {
|
|
206
204
|
config.dev.client ||= {};
|
|
207
205
|
config.dev.client.port = config.server.port;
|
|
208
206
|
}
|
|
209
207
|
// Change the default assetPrefix to `true` for remote modules.
|
|
210
208
|
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
211
209
|
const originalConfig = api.getRsbuildConfig('original');
|
|
212
|
-
if (
|
|
210
|
+
if (originalConfig.dev?.assetPrefix === undefined && config.dev.assetPrefix === config.server?.base) {
|
|
213
211
|
config.dev.assetPrefix = true;
|
|
214
212
|
}
|
|
215
213
|
}
|
|
216
214
|
if (isSSR) {
|
|
217
|
-
|
|
218
|
-
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[external_utils_js_namespaceObject.SSR_ENV_NAME]) {
|
|
215
|
+
if (config.environments?.[external_utils_js_namespaceObject.SSR_ENV_NAME]) {
|
|
219
216
|
throw new Error(`'${external_utils_js_namespaceObject.SSR_ENV_NAME}' environment is already defined.Please use another name.`);
|
|
220
217
|
}
|
|
221
|
-
const currentEnvironment =
|
|
218
|
+
const currentEnvironment = config.environments?.[environment];
|
|
222
219
|
if (!currentEnvironment) {
|
|
223
220
|
throw new Error(`Can not find environment '${environment}' when enabling SSR.`);
|
|
224
221
|
}
|
|
@@ -230,8 +227,7 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
230
227
|
});
|
|
231
228
|
}
|
|
232
229
|
} else if (target === 'node') {
|
|
233
|
-
|
|
234
|
-
const nodeTargetEnv = (_config_environments2 = config.environments) === null || _config_environments2 === void 0 ? void 0 : _config_environments2[environment];
|
|
230
|
+
const nodeTargetEnv = config.environments?.[environment];
|
|
235
231
|
if (!nodeTargetEnv) {
|
|
236
232
|
const availableEnvironments = Object.keys(config.environments || {});
|
|
237
233
|
const availableEnvironmentsLabel = availableEnvironments.length > 0 ? availableEnvironments.join(', ') : '(none)';
|
|
@@ -334,12 +330,11 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
334
330
|
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
335
331
|
bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
|
|
336
332
|
} else {
|
|
337
|
-
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1, _bundlerConfig_output2;
|
|
338
333
|
// mf
|
|
339
|
-
(0,external_utils_js_namespaceObject.autoDeleteSplitChunkCacheGroups)(moduleFederationOptions, bundlerConfig
|
|
334
|
+
(0,external_utils_js_namespaceObject.autoDeleteSplitChunkCacheGroups)(moduleFederationOptions, bundlerConfig?.optimization?.splitChunks);
|
|
340
335
|
(0,external_utils_js_namespaceObject.addDataFetchExposes)(moduleFederationOptions.exposes, shouldUseSSRPluginConfig);
|
|
341
336
|
const ssrModuleFederationOptions = shouldUseSSRPluginConfig ? (0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions) : undefined;
|
|
342
|
-
|
|
337
|
+
delete bundlerConfig.optimization?.runtimeChunk;
|
|
343
338
|
const externals = bundlerConfig.externals;
|
|
344
339
|
if (Array.isArray(externals)) {
|
|
345
340
|
const sharedModules = new Set();
|
|
@@ -380,23 +375,22 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
380
375
|
}
|
|
381
376
|
}
|
|
382
377
|
}
|
|
383
|
-
if (!
|
|
384
|
-
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name}
|
|
378
|
+
if (!bundlerConfig.output?.chunkLoadingGlobal && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig && target !== 'node') {
|
|
379
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name}`;
|
|
385
380
|
}
|
|
386
381
|
if (isNodeTargetEnvironmentConfig) {
|
|
387
382
|
(0,ssr_js_namespaceObject.patchNodeConfig)(bundlerConfig, ssrModuleFederationOptions ?? moduleFederationOptions);
|
|
388
383
|
}
|
|
389
384
|
// `uniqueName` is required for react refresh to work
|
|
390
|
-
if (!
|
|
385
|
+
if (!bundlerConfig.output?.uniqueName) {
|
|
391
386
|
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
392
387
|
}
|
|
393
388
|
// Set default publicPath to 'auto' if not explicitly configured
|
|
394
389
|
// This allows remote chunks to load from the same origin as the remote application's manifest
|
|
395
|
-
if (
|
|
390
|
+
if (bundlerConfig.output?.publicPath === undefined && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
|
|
396
391
|
bundlerConfig.output.publicPath = 'auto';
|
|
397
392
|
}
|
|
398
393
|
if (!bundlerConfig.plugins.find((p)=>p && p.name === rspack_namespaceObject.PLUGIN_NAME)) {
|
|
399
|
-
var _bundlerConfig_output3;
|
|
400
394
|
if (shouldUseSSRPluginConfig) {
|
|
401
395
|
const ssrMFConfig = ssrModuleFederationOptions ?? (0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions);
|
|
402
396
|
generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack_namespaceObject.ModuleFederationPlugin(ssrMFConfig);
|
|
@@ -424,7 +418,7 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
424
418
|
return;
|
|
425
419
|
}
|
|
426
420
|
generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack_namespaceObject.ModuleFederationPlugin(moduleFederationOptions);
|
|
427
|
-
generateMergedStatsAndManifestOptions.options.distOutputDir =
|
|
421
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = bundlerConfig.output?.path || '';
|
|
428
422
|
generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
|
|
429
423
|
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
430
424
|
}
|
|
@@ -466,9 +460,9 @@ exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
|
|
|
466
460
|
exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
|
|
467
461
|
exports.isMFFormat = __webpack_exports__.isMFFormat;
|
|
468
462
|
exports.pluginModuleFederation = __webpack_exports__.pluginModuleFederation;
|
|
469
|
-
for(var
|
|
470
|
-
if(["PLUGIN_NAME","RSBUILD_PLUGIN_MODULE_FEDERATION_NAME","SSR_DIR","TreeShakingSharedPlugin","createModuleFederationConfig","isMFFormat","pluginModuleFederation"].indexOf(
|
|
471
|
-
exports[
|
|
463
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
464
|
+
if(["PLUGIN_NAME","RSBUILD_PLUGIN_MODULE_FEDERATION_NAME","SSR_DIR","TreeShakingSharedPlugin","createModuleFederationConfig","isMFFormat","pluginModuleFederation"].indexOf(__rspack_i) === -1) {
|
|
465
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
472
466
|
}
|
|
473
467
|
}
|
|
474
468
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/cli/index.mjs
CHANGED
|
@@ -6,21 +6,13 @@ import { SSR_DIR, SSR_ENV_NAME, addDataFetchExposes, autoDeleteSplitChunkCacheGr
|
|
|
6
6
|
import { CALL_NAME_MAP, RSPRESS_BUNDLER_CONFIG_NAME, RSPRESS_SSG_MD_ENV_NAME, RSPRESS_SSR_DIR } from "../constant.mjs";
|
|
7
7
|
import { patchNodeConfig, patchToolsTspack } from "../utils/ssr.mjs";
|
|
8
8
|
|
|
9
|
-
;// CONCATENATED MODULE: external "@module-federation/enhanced"
|
|
10
9
|
|
|
11
|
-
;// CONCATENATED MODULE: external "@module-federation/enhanced/rspack"
|
|
12
10
|
|
|
13
|
-
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
14
11
|
|
|
15
|
-
;// CONCATENATED MODULE: external "../logger.mjs"
|
|
16
12
|
|
|
17
|
-
;// CONCATENATED MODULE: external "../utils.mjs"
|
|
18
13
|
|
|
19
|
-
;// CONCATENATED MODULE: external "../constant.mjs"
|
|
20
14
|
|
|
21
|
-
;// CONCATENATED MODULE: external "../utils/ssr.mjs"
|
|
22
15
|
|
|
23
|
-
;// CONCATENATED MODULE: ./src/cli/index.ts
|
|
24
16
|
|
|
25
17
|
|
|
26
18
|
|
|
@@ -54,15 +46,13 @@ const resolveDefaultEnvironmentName = ({ callerName, target })=>{
|
|
|
54
46
|
return DEFAULT_WEB_ENVIRONMENT_NAME;
|
|
55
47
|
};
|
|
56
48
|
function isStoryBook(rsbuildConfig) {
|
|
57
|
-
|
|
58
|
-
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')) {
|
|
49
|
+
if (rsbuildConfig.plugins?.find((p)=>p && 'name' in p && p.name === 'module-federation-storybook-plugin')) {
|
|
59
50
|
return true;
|
|
60
51
|
}
|
|
61
52
|
return false;
|
|
62
53
|
}
|
|
63
54
|
function isMFFormat(bundlerConfig) {
|
|
64
|
-
|
|
65
|
-
const library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
55
|
+
const library = bundlerConfig.output?.library;
|
|
66
56
|
if (bundlerConfig.name === SSR_ENV_NAME) {
|
|
67
57
|
return true;
|
|
68
58
|
}
|
|
@@ -79,7 +69,7 @@ const isRspressSSGConfig = (bundlerConfigName)=>{
|
|
|
79
69
|
const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
80
70
|
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
81
71
|
setup: (api)=>{
|
|
82
|
-
if (!
|
|
72
|
+
if (!moduleFederationOptions?.name) {
|
|
83
73
|
throw new Error('The module federation option "name" is required in @module-federation/rsbuild-plugin.');
|
|
84
74
|
}
|
|
85
75
|
const { target = 'web', ssr = undefined, ssrDir = SSR_DIR, environment: configuredEnvironment } = rsbuildOptions || {};
|
|
@@ -99,12 +89,11 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
99
89
|
target
|
|
100
90
|
});
|
|
101
91
|
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
102
|
-
var _rsbuildConfig_environments;
|
|
103
92
|
if (!isRslib && !isRspress) {
|
|
104
93
|
throw new Error(`'target' option is only supported in Rslib.`);
|
|
105
94
|
}
|
|
106
95
|
const rsbuildConfig = api.getRsbuildConfig();
|
|
107
|
-
if (!isRspress && (!
|
|
96
|
+
if (!isRspress && (!rsbuildConfig.environments?.[environment] || Object.keys(rsbuildConfig.environments).some((key)=>key.startsWith(environment) && key !== environment))) {
|
|
108
97
|
throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
|
|
109
98
|
}
|
|
110
99
|
setSSREnv();
|
|
@@ -128,14 +117,13 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
128
117
|
}
|
|
129
118
|
// Change some default configs for remote modules
|
|
130
119
|
if (moduleFederationOptions.exposes) {
|
|
131
|
-
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
132
120
|
config.dev ||= {};
|
|
133
121
|
config.server ||= {};
|
|
134
122
|
const userConfig = api.getRsbuildConfig('original');
|
|
135
123
|
// Allow remote modules to be loaded by setting CORS headers
|
|
136
124
|
// This is required for MF to work properly across different origins
|
|
137
125
|
config.server.headers ||= {};
|
|
138
|
-
if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof
|
|
126
|
+
if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof userConfig.server?.cors === 'object' && userConfig.server.cors.origin)) {
|
|
139
127
|
const corsWarnMsgs = [
|
|
140
128
|
'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.',
|
|
141
129
|
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
@@ -145,23 +133,22 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
145
133
|
}
|
|
146
134
|
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
147
135
|
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
148
|
-
if (
|
|
136
|
+
if (config.server?.port && !config.dev.client?.port) {
|
|
149
137
|
config.dev.client ||= {};
|
|
150
138
|
config.dev.client.port = config.server.port;
|
|
151
139
|
}
|
|
152
140
|
// Change the default assetPrefix to `true` for remote modules.
|
|
153
141
|
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
154
142
|
const originalConfig = api.getRsbuildConfig('original');
|
|
155
|
-
if (
|
|
143
|
+
if (originalConfig.dev?.assetPrefix === undefined && config.dev.assetPrefix === config.server?.base) {
|
|
156
144
|
config.dev.assetPrefix = true;
|
|
157
145
|
}
|
|
158
146
|
}
|
|
159
147
|
if (isSSR) {
|
|
160
|
-
|
|
161
|
-
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[SSR_ENV_NAME]) {
|
|
148
|
+
if (config.environments?.[SSR_ENV_NAME]) {
|
|
162
149
|
throw new Error(`'${SSR_ENV_NAME}' environment is already defined.Please use another name.`);
|
|
163
150
|
}
|
|
164
|
-
const currentEnvironment =
|
|
151
|
+
const currentEnvironment = config.environments?.[environment];
|
|
165
152
|
if (!currentEnvironment) {
|
|
166
153
|
throw new Error(`Can not find environment '${environment}' when enabling SSR.`);
|
|
167
154
|
}
|
|
@@ -173,8 +160,7 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
173
160
|
});
|
|
174
161
|
}
|
|
175
162
|
} else if (target === 'node') {
|
|
176
|
-
|
|
177
|
-
const nodeTargetEnv = (_config_environments2 = config.environments) === null || _config_environments2 === void 0 ? void 0 : _config_environments2[environment];
|
|
163
|
+
const nodeTargetEnv = config.environments?.[environment];
|
|
178
164
|
if (!nodeTargetEnv) {
|
|
179
165
|
const availableEnvironments = Object.keys(config.environments || {});
|
|
180
166
|
const availableEnvironmentsLabel = availableEnvironments.length > 0 ? availableEnvironments.join(', ') : '(none)';
|
|
@@ -204,8 +190,8 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
204
190
|
nodeEnvironmentName: undefined
|
|
205
191
|
},
|
|
206
192
|
assetResources: {},
|
|
207
|
-
isSSRConfig,
|
|
208
|
-
isRspressSSGConfig
|
|
193
|
+
isSSRConfig: isSSRConfig,
|
|
194
|
+
isRspressSSGConfig: isRspressSSGConfig
|
|
209
195
|
};
|
|
210
196
|
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
211
197
|
const defaultBrowserEnvironmentName = environment;
|
|
@@ -277,12 +263,11 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
277
263
|
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
278
264
|
bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
|
|
279
265
|
} else {
|
|
280
|
-
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1, _bundlerConfig_output2;
|
|
281
266
|
// mf
|
|
282
|
-
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig
|
|
267
|
+
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig?.optimization?.splitChunks);
|
|
283
268
|
addDataFetchExposes(moduleFederationOptions.exposes, shouldUseSSRPluginConfig);
|
|
284
269
|
const ssrModuleFederationOptions = shouldUseSSRPluginConfig ? createSSRMFConfig(moduleFederationOptions) : undefined;
|
|
285
|
-
|
|
270
|
+
delete bundlerConfig.optimization?.runtimeChunk;
|
|
286
271
|
const externals = bundlerConfig.externals;
|
|
287
272
|
if (Array.isArray(externals)) {
|
|
288
273
|
const sharedModules = new Set();
|
|
@@ -323,23 +308,22 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
323
308
|
}
|
|
324
309
|
}
|
|
325
310
|
}
|
|
326
|
-
if (!
|
|
327
|
-
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name}
|
|
311
|
+
if (!bundlerConfig.output?.chunkLoadingGlobal && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig && target !== 'node') {
|
|
312
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name}`;
|
|
328
313
|
}
|
|
329
314
|
if (isNodeTargetEnvironmentConfig) {
|
|
330
315
|
patchNodeConfig(bundlerConfig, ssrModuleFederationOptions ?? moduleFederationOptions);
|
|
331
316
|
}
|
|
332
317
|
// `uniqueName` is required for react refresh to work
|
|
333
|
-
if (!
|
|
318
|
+
if (!bundlerConfig.output?.uniqueName) {
|
|
334
319
|
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
335
320
|
}
|
|
336
321
|
// Set default publicPath to 'auto' if not explicitly configured
|
|
337
322
|
// This allows remote chunks to load from the same origin as the remote application's manifest
|
|
338
|
-
if (
|
|
323
|
+
if (bundlerConfig.output?.publicPath === undefined && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
|
|
339
324
|
bundlerConfig.output.publicPath = 'auto';
|
|
340
325
|
}
|
|
341
326
|
if (!bundlerConfig.plugins.find((p)=>p && p.name === PLUGIN_NAME)) {
|
|
342
|
-
var _bundlerConfig_output3;
|
|
343
327
|
if (shouldUseSSRPluginConfig) {
|
|
344
328
|
const ssrMFConfig = ssrModuleFederationOptions ?? createSSRMFConfig(moduleFederationOptions);
|
|
345
329
|
generateMergedStatsAndManifestOptions.options.nodePlugin = new ModuleFederationPlugin(ssrMFConfig);
|
|
@@ -367,7 +351,7 @@ const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
|
367
351
|
return;
|
|
368
352
|
}
|
|
369
353
|
generateMergedStatsAndManifestOptions.options.browserPlugin = new ModuleFederationPlugin(moduleFederationOptions);
|
|
370
|
-
generateMergedStatsAndManifestOptions.options.distOutputDir =
|
|
354
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = bundlerConfig.output?.path || '';
|
|
371
355
|
generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
|
|
372
356
|
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
373
357
|
}
|
package/dist/constant.js
CHANGED
|
@@ -9,15 +9,18 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
|
9
9
|
// The require scope
|
|
10
10
|
var __webpack_require__ = {};
|
|
11
11
|
|
|
12
|
-
/************************************************************************/
|
|
13
12
|
// webpack/runtime/define_property_getters
|
|
14
13
|
(() => {
|
|
15
|
-
__webpack_require__.d = (exports,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
|
21
24
|
};
|
|
22
25
|
})();
|
|
23
26
|
// webpack/runtime/has_own_property
|
|
@@ -34,18 +37,8 @@ __webpack_require__.r = (exports) => {
|
|
|
34
37
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
38
|
};
|
|
36
39
|
})();
|
|
37
|
-
/************************************************************************/
|
|
38
40
|
var __webpack_exports__ = {};
|
|
39
41
|
__webpack_require__.r(__webpack_exports__);
|
|
40
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
41
|
-
CALL_NAME_MAP: () => (CALL_NAME_MAP),
|
|
42
|
-
DATA_FETCH_CLIENT_SUFFIX: () => (DATA_FETCH_CLIENT_SUFFIX),
|
|
43
|
-
DATA_FETCH_IDENTIFIER: () => (DATA_FETCH_IDENTIFIER),
|
|
44
|
-
DEFAULT_ASSET_PREFIX: () => (DEFAULT_ASSET_PREFIX),
|
|
45
|
-
RSPRESS_BUNDLER_CONFIG_NAME: () => (RSPRESS_BUNDLER_CONFIG_NAME),
|
|
46
|
-
RSPRESS_SSG_MD_ENV_NAME: () => (RSPRESS_SSG_MD_ENV_NAME),
|
|
47
|
-
RSPRESS_SSR_DIR: () => (RSPRESS_SSR_DIR)
|
|
48
|
-
});
|
|
49
42
|
const DEFAULT_ASSET_PREFIX = '/';
|
|
50
43
|
const DATA_FETCH_IDENTIFIER = 'data';
|
|
51
44
|
const DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
@@ -57,6 +50,17 @@ const RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
|
57
50
|
const RSPRESS_SSG_MD_ENV_NAME = 'node_md';
|
|
58
51
|
const RSPRESS_SSR_DIR = 'ssr';
|
|
59
52
|
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
}, {
|
|
55
|
+
CALL_NAME_MAP: CALL_NAME_MAP,
|
|
56
|
+
DATA_FETCH_CLIENT_SUFFIX: DATA_FETCH_CLIENT_SUFFIX,
|
|
57
|
+
DATA_FETCH_IDENTIFIER: DATA_FETCH_IDENTIFIER,
|
|
58
|
+
DEFAULT_ASSET_PREFIX: DEFAULT_ASSET_PREFIX,
|
|
59
|
+
RSPRESS_BUNDLER_CONFIG_NAME: RSPRESS_BUNDLER_CONFIG_NAME,
|
|
60
|
+
RSPRESS_SSG_MD_ENV_NAME: RSPRESS_SSG_MD_ENV_NAME,
|
|
61
|
+
RSPRESS_SSR_DIR: RSPRESS_SSR_DIR
|
|
62
|
+
});
|
|
63
|
+
|
|
60
64
|
exports.CALL_NAME_MAP = __webpack_exports__.CALL_NAME_MAP;
|
|
61
65
|
exports.DATA_FETCH_CLIENT_SUFFIX = __webpack_exports__.DATA_FETCH_CLIENT_SUFFIX;
|
|
62
66
|
exports.DATA_FETCH_IDENTIFIER = __webpack_exports__.DATA_FETCH_IDENTIFIER;
|
|
@@ -64,9 +68,9 @@ exports.DEFAULT_ASSET_PREFIX = __webpack_exports__.DEFAULT_ASSET_PREFIX;
|
|
|
64
68
|
exports.RSPRESS_BUNDLER_CONFIG_NAME = __webpack_exports__.RSPRESS_BUNDLER_CONFIG_NAME;
|
|
65
69
|
exports.RSPRESS_SSG_MD_ENV_NAME = __webpack_exports__.RSPRESS_SSG_MD_ENV_NAME;
|
|
66
70
|
exports.RSPRESS_SSR_DIR = __webpack_exports__.RSPRESS_SSR_DIR;
|
|
67
|
-
for(var
|
|
68
|
-
if(["CALL_NAME_MAP","DATA_FETCH_CLIENT_SUFFIX","DATA_FETCH_IDENTIFIER","DEFAULT_ASSET_PREFIX","RSPRESS_BUNDLER_CONFIG_NAME","RSPRESS_SSG_MD_ENV_NAME","RSPRESS_SSR_DIR"].indexOf(
|
|
69
|
-
exports[
|
|
71
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
72
|
+
if(["CALL_NAME_MAP","DATA_FETCH_CLIENT_SUFFIX","DATA_FETCH_IDENTIFIER","DEFAULT_ASSET_PREFIX","RSPRESS_BUNDLER_CONFIG_NAME","RSPRESS_SSG_MD_ENV_NAME","RSPRESS_SSR_DIR"].indexOf(__rspack_i) === -1) {
|
|
73
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/constant.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,13 +7,12 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
|
7
7
|
})();
|
|
8
8
|
;
|
|
9
9
|
var __webpack_modules__ = ({
|
|
10
|
-
"./cli/index"
|
|
10
|
+
"./cli/index"(module) {
|
|
11
11
|
module.exports = require("./cli/index.js");
|
|
12
12
|
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
14
|
|
|
15
15
|
});
|
|
16
|
-
/************************************************************************/
|
|
17
16
|
// The module cache
|
|
18
17
|
var __webpack_module_cache__ = {};
|
|
19
18
|
|
|
@@ -37,7 +36,6 @@ return module.exports;
|
|
|
37
36
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
/************************************************************************/
|
|
41
39
|
// webpack/runtime/compat_get_default_export
|
|
42
40
|
(() => {
|
|
43
41
|
// getDefaultExport function for compatibility with non-ESM modules
|
|
@@ -52,12 +50,16 @@ __webpack_require__.n = (module) => {
|
|
|
52
50
|
})();
|
|
53
51
|
// webpack/runtime/define_property_getters
|
|
54
52
|
(() => {
|
|
55
|
-
__webpack_require__.d = (exports,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
54
|
+
var define = (defs, kind) => {
|
|
55
|
+
for(var key in defs) {
|
|
56
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
57
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
define(getters, "get");
|
|
62
|
+
define(values, "value");
|
|
61
63
|
};
|
|
62
64
|
})();
|
|
63
65
|
// webpack/runtime/has_own_property
|
|
@@ -74,22 +76,21 @@ __webpack_require__.r = (exports) => {
|
|
|
74
76
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
75
77
|
};
|
|
76
78
|
})();
|
|
77
|
-
/************************************************************************/
|
|
78
79
|
var __webpack_exports__ = {};
|
|
79
80
|
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
80
81
|
(() => {
|
|
81
82
|
__webpack_require__.r(__webpack_exports__);
|
|
82
|
-
/*
|
|
83
|
-
/*
|
|
83
|
+
/* import */ var _cli_index__rspack_import_0 = __webpack_require__("./cli/index");
|
|
84
|
+
/* import */ var _cli_index__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_cli_index__rspack_import_0);
|
|
84
85
|
|
|
85
|
-
/*
|
|
86
|
-
/*
|
|
87
|
-
/*
|
|
86
|
+
/* reexport */ var __rspack_reexport = {};
|
|
87
|
+
/* reexport */ for( const __rspack_import_key in _cli_index__rspack_import_0) if(__rspack_import_key !== "default") __rspack_reexport[__rspack_import_key] =() => _cli_index__rspack_import_0[__rspack_import_key]
|
|
88
|
+
/* reexport */ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
})();
|
|
91
92
|
|
|
92
|
-
for(var
|
|
93
|
-
exports[
|
|
93
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
94
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
94
95
|
}
|
|
95
96
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/index.mjs
CHANGED
package/dist/logger.js
CHANGED
|
@@ -9,15 +9,18 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
|
9
9
|
// The require scope
|
|
10
10
|
var __webpack_require__ = {};
|
|
11
11
|
|
|
12
|
-
/************************************************************************/
|
|
13
12
|
// webpack/runtime/define_property_getters
|
|
14
13
|
(() => {
|
|
15
|
-
__webpack_require__.d = (exports,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
|
21
24
|
};
|
|
22
25
|
})();
|
|
23
26
|
// webpack/runtime/has_own_property
|
|
@@ -34,7 +37,6 @@ __webpack_require__.r = (exports) => {
|
|
|
34
37
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
38
|
};
|
|
36
39
|
})();
|
|
37
|
-
/************************************************************************/
|
|
38
40
|
var __webpack_exports__ = {};
|
|
39
41
|
// ESM COMPAT FLAG
|
|
40
42
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -49,12 +51,12 @@ const sdk_namespaceObject = require("@module-federation/sdk");
|
|
|
49
51
|
;// CONCATENATED MODULE: ./src/logger.ts
|
|
50
52
|
|
|
51
53
|
const logger = (0,sdk_namespaceObject.createLogger)('[ Module Federation Rsbuild Plugin ]');
|
|
52
|
-
/*
|
|
54
|
+
/* export default */ const src_logger = (logger);
|
|
53
55
|
|
|
54
56
|
exports["default"] = __webpack_exports__["default"];
|
|
55
|
-
for(var
|
|
56
|
-
if(["default"].indexOf(
|
|
57
|
-
exports[
|
|
57
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
58
|
+
if(["default"].indexOf(__rspack_i) === -1) {
|
|
59
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/logger.mjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { createLogger } from "@module-federation/sdk";
|
|
2
2
|
|
|
3
|
-
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
4
3
|
|
|
5
|
-
;// CONCATENATED MODULE: ./src/logger.ts
|
|
6
4
|
|
|
7
5
|
const logger = createLogger('[ Module Federation Rsbuild Plugin ]');
|
|
8
|
-
/*
|
|
6
|
+
/* export default */ const src_logger = (logger);
|
|
9
7
|
|
|
10
|
-
export
|
|
8
|
+
export default src_logger;
|