@module-federation/rsbuild-plugin 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +429 -0
- package/dist/cli/index.mjs +360 -0
- package/dist/constant.d.ts +1 -0
- package/dist/constant.js +48 -35
- package/dist/constant.mjs +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +86 -528
- package/dist/index.mjs +5 -470
- package/dist/logger.js +60 -0
- package/dist/logger.mjs +10 -0
- package/dist/utils/addDataFetchExposes.js +126 -0
- package/dist/utils/addDataFetchExposes.mjs +65 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.js +99 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.mjs +53 -0
- package/dist/utils/index.js +109 -0
- package/dist/utils/index.mjs +31 -0
- package/dist/utils/manifest.js +113 -0
- package/dist/utils/manifest.mjs +50 -0
- package/dist/utils/ssr.js +230 -0
- package/dist/utils/ssr.mjs +152 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +86 -291
- package/dist/utils.mjs +5 -222
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ npm install @module-federation/enhanced
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### Rsbuild App
|
|
14
|
-
|
|
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';
|
|
@@ -34,7 +35,8 @@ export default defineConfig({
|
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
### Rslib Module
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
```js
|
|
38
40
|
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
|
|
39
41
|
import { defineConfig } from '@rslib/core';
|
|
40
42
|
|
|
@@ -70,3 +72,7 @@ export default defineConfig({
|
|
|
70
72
|
],
|
|
71
73
|
});
|
|
72
74
|
```
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
See [https://module-federation.io/guide/build-plugins/plugins-rsbuild.html](https://module-federation.io/guide/build-plugins/plugins-rsbuild.html) fordetails.
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -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) =>
|
|
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,429 @@
|
|
|
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
|
+
function isStoryBook(rsbuildConfig) {
|
|
101
|
+
var _rsbuildConfig_plugins;
|
|
102
|
+
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')) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
function isMFFormat(bundlerConfig) {
|
|
108
|
+
var _bundlerConfig_output;
|
|
109
|
+
const library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
110
|
+
if (bundlerConfig.name === external_utils_js_namespaceObject.SSR_ENV_NAME) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
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
|
|
114
|
+
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
115
|
+
}
|
|
116
|
+
const isSSRConfig = (bundlerConfigName)=>Boolean(bundlerConfigName === external_utils_js_namespaceObject.SSR_ENV_NAME);
|
|
117
|
+
const isRspressSSGConfig = (bundlerConfigName)=>{
|
|
118
|
+
return [
|
|
119
|
+
external_constant_js_namespaceObject.RSPRESS_BUNDLER_CONFIG_NAME,
|
|
120
|
+
external_constant_js_namespaceObject.RSPRESS_SSG_MD_ENV_NAME
|
|
121
|
+
].includes(bundlerConfigName || '');
|
|
122
|
+
};
|
|
123
|
+
const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
124
|
+
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
125
|
+
setup: (api)=>{
|
|
126
|
+
const { target = 'web', ssr = undefined, ssrDir = external_utils_js_namespaceObject.SSR_DIR, environment = DEFAULT_MF_ENVIRONMENT_NAME } = rsbuildOptions || {};
|
|
127
|
+
if (ssr) {
|
|
128
|
+
throw new Error("The `ssr` option is deprecated. If you want to enable SSR, please use `target: 'dual'` instead.");
|
|
129
|
+
}
|
|
130
|
+
const { callerName } = api.context;
|
|
131
|
+
const originalRsbuildConfig = api.getRsbuildConfig();
|
|
132
|
+
if (!callerName) {
|
|
133
|
+
throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
134
|
+
}
|
|
135
|
+
const isRslib = callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSLIB;
|
|
136
|
+
const isRspress = callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSPRESS;
|
|
137
|
+
const isSSR = target === 'dual';
|
|
138
|
+
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
139
|
+
var _rsbuildConfig_environments;
|
|
140
|
+
if (!isRslib && !isRspress) {
|
|
141
|
+
throw new Error(`'target' option is only supported in Rslib.`);
|
|
142
|
+
}
|
|
143
|
+
const rsbuildConfig = api.getRsbuildConfig();
|
|
144
|
+
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))) {
|
|
145
|
+
throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
|
|
146
|
+
}
|
|
147
|
+
(0,external_utils_js_namespaceObject.setSSREnv)();
|
|
148
|
+
}
|
|
149
|
+
const sharedOptions = (0,enhanced_namespaceObject.parseOptions)(moduleFederationOptions.shared || [], (item, key)=>{
|
|
150
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
151
|
+
const config = item === key || !(0,sdk_namespaceObject.isRequiredVersion)(item) ? {
|
|
152
|
+
import: item
|
|
153
|
+
} : {
|
|
154
|
+
import: key,
|
|
155
|
+
requiredVersion: item
|
|
156
|
+
};
|
|
157
|
+
return config;
|
|
158
|
+
}, (item)=>item);
|
|
159
|
+
// shared[0] is the shared name
|
|
160
|
+
const shared = sharedOptions.map((shared)=>shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0]);
|
|
161
|
+
api.modifyRsbuildConfig((config)=>{
|
|
162
|
+
// skip storybook
|
|
163
|
+
if (isStoryBook(config)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Change some default configs for remote modules
|
|
167
|
+
if (moduleFederationOptions.exposes) {
|
|
168
|
+
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
169
|
+
config.dev ||= {};
|
|
170
|
+
config.server ||= {};
|
|
171
|
+
const userConfig = api.getRsbuildConfig('original');
|
|
172
|
+
// Allow remote modules to be loaded by setting CORS headers
|
|
173
|
+
// This is required for MF to work properly across different origins
|
|
174
|
+
config.server.headers ||= {};
|
|
175
|
+
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)) {
|
|
176
|
+
const corsWarnMsgs = [
|
|
177
|
+
'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.',
|
|
178
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
179
|
+
];
|
|
180
|
+
!isRslib && !isRspress && external_logger_js_default().warn(corsWarnMsgs.join('\n'));
|
|
181
|
+
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
182
|
+
}
|
|
183
|
+
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
184
|
+
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
185
|
+
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)) {
|
|
186
|
+
config.dev.client ||= {};
|
|
187
|
+
config.dev.client.port = config.server.port;
|
|
188
|
+
}
|
|
189
|
+
// Change the default assetPrefix to `true` for remote modules.
|
|
190
|
+
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
191
|
+
const originalConfig = api.getRsbuildConfig('original');
|
|
192
|
+
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)) {
|
|
193
|
+
config.dev.assetPrefix = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (isSSR) {
|
|
197
|
+
var _config_environments, _config_environments1;
|
|
198
|
+
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[external_utils_js_namespaceObject.SSR_ENV_NAME]) {
|
|
199
|
+
throw new Error(`'${external_utils_js_namespaceObject.SSR_ENV_NAME}' environment is already defined.Please use another name.`);
|
|
200
|
+
}
|
|
201
|
+
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);
|
|
202
|
+
const ssgMDEnv = config.environments[external_constant_js_namespaceObject.RSPRESS_SSG_MD_ENV_NAME];
|
|
203
|
+
if (isRspress && ssgMDEnv) {
|
|
204
|
+
(0,ssr_js_namespaceObject.patchToolsTspack)(ssgMDEnv, (config, { environment })=>{
|
|
205
|
+
config.target = 'async-node';
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
} else if (target === 'node') {
|
|
209
|
+
const mfEnv = config.environments[ssr_js_namespaceObject.ENV_NAME];
|
|
210
|
+
(0,ssr_js_namespaceObject.patchToolsTspack)(mfEnv, (config, { environment })=>{
|
|
211
|
+
config.target = 'async-node';
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
api.modifyEnvironmentConfig((config)=>{
|
|
216
|
+
// Module Federation runtime uses ES6+ syntax,
|
|
217
|
+
// adding to include and let SWC transform it
|
|
218
|
+
config.source.include = [
|
|
219
|
+
...config.source.include || [],
|
|
220
|
+
/@module-federation[\\/]/
|
|
221
|
+
];
|
|
222
|
+
return config;
|
|
223
|
+
});
|
|
224
|
+
const generateMergedStatsAndManifestOptions = {
|
|
225
|
+
options: {
|
|
226
|
+
nodePlugin: undefined,
|
|
227
|
+
browserPlugin: undefined,
|
|
228
|
+
rspressSSGPlugin: undefined,
|
|
229
|
+
distOutputDir: undefined,
|
|
230
|
+
browserEnvironmentName: undefined,
|
|
231
|
+
nodeEnvironmentName: undefined
|
|
232
|
+
},
|
|
233
|
+
assetResources: {},
|
|
234
|
+
isSSRConfig,
|
|
235
|
+
isRspressSSGConfig
|
|
236
|
+
};
|
|
237
|
+
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
238
|
+
const defaultBrowserEnvironmentName = environment;
|
|
239
|
+
const assetFileNames = (0,sdk_namespaceObject.getManifestFileName)(moduleFederationOptions.manifest);
|
|
240
|
+
if (moduleFederationOptions.manifest !== false) {
|
|
241
|
+
api.processAssets({
|
|
242
|
+
stage: 'report'
|
|
243
|
+
}, ({ assets, environment: envContext })=>{
|
|
244
|
+
const expectedBrowserEnv = generateMergedStatsAndManifestOptions.options.browserEnvironmentName ?? defaultBrowserEnvironmentName;
|
|
245
|
+
const expectedNodeEnv = generateMergedStatsAndManifestOptions.options.nodeEnvironmentName ?? external_utils_js_namespaceObject.SSR_ENV_NAME;
|
|
246
|
+
const envName = envContext.name;
|
|
247
|
+
if (envName !== expectedBrowserEnv && envName !== expectedNodeEnv) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
251
|
+
const targetResources = assetResources[envName] || (assetResources[envName] = {});
|
|
252
|
+
const statsAsset = assets[assetFileNames.statsFileName];
|
|
253
|
+
if (statsAsset) {
|
|
254
|
+
try {
|
|
255
|
+
const raw = statsAsset.source();
|
|
256
|
+
const content = typeof raw === 'string' ? raw : raw.toString();
|
|
257
|
+
targetResources.stats = {
|
|
258
|
+
data: JSON.parse(content),
|
|
259
|
+
filename: assetFileNames.statsFileName
|
|
260
|
+
};
|
|
261
|
+
} catch (err) {
|
|
262
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
263
|
+
external_logger_js_default().error(`Failed to parse stats asset "${assetFileNames.statsFileName}" for environment "${envName}": ${message} `);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const manifestAsset = assets[assetFileNames.manifestFileName];
|
|
267
|
+
if (manifestAsset) {
|
|
268
|
+
try {
|
|
269
|
+
const raw = manifestAsset.source();
|
|
270
|
+
const content = typeof raw === 'string' ? raw : raw.toString();
|
|
271
|
+
targetResources.manifest = {
|
|
272
|
+
data: JSON.parse(content),
|
|
273
|
+
filename: assetFileNames.manifestFileName
|
|
274
|
+
};
|
|
275
|
+
} catch (err) {
|
|
276
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
277
|
+
external_logger_js_default().error(`Failed to parse manifest asset "${assetFileNames.manifestFileName}" for environment "${envName}": ${message} `);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
|
|
283
|
+
if (!bundlerConfigs) {
|
|
284
|
+
throw new Error('Can not get bundlerConfigs!');
|
|
285
|
+
}
|
|
286
|
+
bundlerConfigs.forEach((bundlerConfig)=>{
|
|
287
|
+
if (!isMFFormat(bundlerConfig) && !isRspress) {
|
|
288
|
+
return;
|
|
289
|
+
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
290
|
+
bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
|
|
291
|
+
} else {
|
|
292
|
+
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1, _bundlerConfig_output2;
|
|
293
|
+
// mf
|
|
294
|
+
(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);
|
|
295
|
+
(0,external_utils_js_namespaceObject.addDataFetchExposes)(moduleFederationOptions.exposes, isSSRConfig(bundlerConfig.name));
|
|
296
|
+
(_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? true : delete _bundlerConfig_optimization1.runtimeChunk;
|
|
297
|
+
const externals = bundlerConfig.externals;
|
|
298
|
+
if (Array.isArray(externals)) {
|
|
299
|
+
const sharedModules = new Set();
|
|
300
|
+
bundlerConfig.externals = externals.filter((ext)=>{
|
|
301
|
+
let sharedModule;
|
|
302
|
+
if ((0,external_utils_js_namespaceObject.isRegExp)(ext)) {
|
|
303
|
+
const match = shared.some((dep)=>{
|
|
304
|
+
if (ext.test(dep) || ext.test((external_package_json_default()).name)) {
|
|
305
|
+
sharedModule = dep;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
});
|
|
310
|
+
match && sharedModule && sharedModules.add(sharedModule);
|
|
311
|
+
return !match;
|
|
312
|
+
}
|
|
313
|
+
if (typeof ext === 'string') {
|
|
314
|
+
if (ext === (external_package_json_default()).name) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
const match = shared.some((dep)=>{
|
|
318
|
+
if (dep === ext) {
|
|
319
|
+
sharedModule = dep;
|
|
320
|
+
}
|
|
321
|
+
return dep === ext;
|
|
322
|
+
});
|
|
323
|
+
if (match) {
|
|
324
|
+
sharedModule && sharedModules.add(sharedModule);
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
return true;
|
|
330
|
+
});
|
|
331
|
+
if (sharedModules.size > 0) {
|
|
332
|
+
for (const sharedModule of sharedModules){
|
|
333
|
+
external_logger_js_default().log(`${sharedModule} is removed from externals because it is a shared module.`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !isSSRConfig(bundlerConfig.name) && !isRspressSSGConfig(bundlerConfig.name) && target !== 'node') {
|
|
338
|
+
bundlerConfig.output.chunkLoading = 'jsonp';
|
|
339
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name} `;
|
|
340
|
+
}
|
|
341
|
+
if (target === 'node' && isMFFormat(bundlerConfig)) {
|
|
342
|
+
(0,ssr_js_namespaceObject.patchNodeConfig)(bundlerConfig, moduleFederationOptions);
|
|
343
|
+
(0,ssr_js_namespaceObject.patchNodeMFConfig)(moduleFederationOptions);
|
|
344
|
+
}
|
|
345
|
+
// `uniqueName` is required for react refresh to work
|
|
346
|
+
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
347
|
+
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
348
|
+
}
|
|
349
|
+
// Set default publicPath to 'auto' if not explicitly configured
|
|
350
|
+
// This allows remote chunks to load from the same origin as the remote application's manifest
|
|
351
|
+
if (((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.publicPath) === undefined && !isSSRConfig(bundlerConfig.name) && !isRspressSSGConfig(bundlerConfig.name)) {
|
|
352
|
+
bundlerConfig.output.publicPath = 'auto';
|
|
353
|
+
}
|
|
354
|
+
if (!bundlerConfig.plugins.find((p)=>p && p.name === rspack_namespaceObject.PLUGIN_NAME)) {
|
|
355
|
+
var _bundlerConfig_output3;
|
|
356
|
+
if (isSSRConfig(bundlerConfig.name)) {
|
|
357
|
+
generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack_namespaceObject.ModuleFederationPlugin((0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions));
|
|
358
|
+
generateMergedStatsAndManifestOptions.options.nodeEnvironmentName = bundlerConfig.name || external_utils_js_namespaceObject.SSR_ENV_NAME;
|
|
359
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
360
|
+
return;
|
|
361
|
+
} else if (isRspressSSGConfig(bundlerConfig.name)) {
|
|
362
|
+
const mfConfig = {
|
|
363
|
+
...(0,external_utils_js_namespaceObject.createSSRMFConfig)(moduleFederationOptions),
|
|
364
|
+
// expose in mf-ssg env
|
|
365
|
+
exposes: {},
|
|
366
|
+
manifest: false,
|
|
367
|
+
library: undefined
|
|
368
|
+
};
|
|
369
|
+
(0,external_utils_js_namespaceObject.patchSSRRspackConfig)(bundlerConfig, mfConfig, external_constant_js_namespaceObject.RSPRESS_SSR_DIR, callerName, false, false);
|
|
370
|
+
bundlerConfig.output ||= {};
|
|
371
|
+
bundlerConfig.output.publicPath = '/';
|
|
372
|
+
// MF depend on asyncChunks
|
|
373
|
+
bundlerConfig.output.asyncChunks = undefined;
|
|
374
|
+
const p = new rspack_namespaceObject.ModuleFederationPlugin(mfConfig);
|
|
375
|
+
if (bundlerConfig.name === external_constant_js_namespaceObject.RSPRESS_BUNDLER_CONFIG_NAME) {
|
|
376
|
+
generateMergedStatsAndManifestOptions.options.rspressSSGPlugin = p;
|
|
377
|
+
}
|
|
378
|
+
bundlerConfig.plugins.push(p);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack_namespaceObject.ModuleFederationPlugin(moduleFederationOptions);
|
|
382
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = ((_bundlerConfig_output3 = bundlerConfig.output) === null || _bundlerConfig_output3 === void 0 ? void 0 : _bundlerConfig_output3.path) || '';
|
|
383
|
+
generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
|
|
384
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
const generateMergedStatsAndManifest = ()=>{
|
|
390
|
+
const { distOutputDir, browserEnvironmentName, nodeEnvironmentName } = generateMergedStatsAndManifestOptions.options;
|
|
391
|
+
if (!distOutputDir || !browserEnvironmentName || !nodeEnvironmentName) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
395
|
+
const browserAssets = assetResources[browserEnvironmentName];
|
|
396
|
+
const nodeAssets = assetResources[nodeEnvironmentName];
|
|
397
|
+
if (!browserAssets || !nodeAssets) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
(0,external_utils_js_namespaceObject.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
|
|
402
|
+
} catch (err) {
|
|
403
|
+
external_logger_js_default().error(err);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
api.onDevCompileDone(()=>{
|
|
407
|
+
generateMergedStatsAndManifest();
|
|
408
|
+
});
|
|
409
|
+
api.onAfterBuild(()=>{
|
|
410
|
+
generateMergedStatsAndManifest();
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
|
|
418
|
+
exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = __webpack_exports__.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
|
|
419
|
+
exports.SSR_DIR = __webpack_exports__.SSR_DIR;
|
|
420
|
+
exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
|
|
421
|
+
exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
|
|
422
|
+
exports.isMFFormat = __webpack_exports__.isMFFormat;
|
|
423
|
+
exports.pluginModuleFederation = __webpack_exports__.pluginModuleFederation;
|
|
424
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
425
|
+
if(["PLUGIN_NAME","RSBUILD_PLUGIN_MODULE_FEDERATION_NAME","SSR_DIR","TreeShakingSharedPlugin","createModuleFederationConfig","isMFFormat","pluginModuleFederation"].indexOf(__webpack_i__) === -1) {
|
|
426
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|