@module-federation/rsbuild-plugin 0.24.1 → 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 +6 -6
package/dist/index.js
CHANGED
|
@@ -1,537 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
(
|
|
7
|
-
__webpack_require__.n = (module)=>{
|
|
8
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
-
__webpack_require__.d(getter, {
|
|
10
|
-
a: getter
|
|
11
|
-
});
|
|
12
|
-
return getter;
|
|
13
|
-
};
|
|
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;
|
|
14
7
|
})();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
-
})();
|
|
26
|
-
(()=>{
|
|
27
|
-
__webpack_require__.r = (exports1)=>{
|
|
28
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
29
|
-
value: 'Module'
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
32
|
-
value: true
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
var __webpack_exports__ = {};
|
|
37
|
-
__webpack_require__.r(__webpack_exports__);
|
|
38
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
-
pluginModuleFederation: ()=>pluginModuleFederation,
|
|
40
|
-
RSBUILD_PLUGIN_MODULE_FEDERATION_NAME: ()=>RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
41
|
-
PLUGIN_NAME: ()=>rspack_namespaceObject.PLUGIN_NAME,
|
|
42
|
-
SSR_DIR: ()=>SSR_DIR,
|
|
43
|
-
isMFFormat: ()=>isMFFormat,
|
|
44
|
-
TreeShakingSharedPlugin: ()=>rspack_namespaceObject.TreeShakingSharedPlugin,
|
|
45
|
-
createModuleFederationConfig: ()=>sdk_namespaceObject.createModuleFederationConfig
|
|
8
|
+
;
|
|
9
|
+
var __webpack_modules__ = ({
|
|
10
|
+
"./cli/index": (function (module) {
|
|
11
|
+
module.exports = require("./cli/index.js");
|
|
12
|
+
|
|
13
|
+
}),
|
|
14
|
+
|
|
46
15
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
16
|
+
/************************************************************************/
|
|
17
|
+
// The module cache
|
|
18
|
+
var __webpack_module_cache__ = {};
|
|
19
|
+
|
|
20
|
+
// The require function
|
|
21
|
+
function __webpack_require__(moduleId) {
|
|
22
|
+
|
|
23
|
+
// Check if module is in cache
|
|
24
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
25
|
+
if (cachedModule !== undefined) {
|
|
26
|
+
return cachedModule.exports;
|
|
27
|
+
}
|
|
28
|
+
// Create a new module (and put it into the cache)
|
|
29
|
+
var module = (__webpack_module_cache__[moduleId] = {
|
|
30
|
+
exports: {}
|
|
31
|
+
});
|
|
32
|
+
// Execute the module function
|
|
33
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
34
|
+
|
|
35
|
+
// Return the exports of the module
|
|
36
|
+
return module.exports;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/************************************************************************/
|
|
41
|
+
// webpack/runtime/compat_get_default_export
|
|
42
|
+
(() => {
|
|
43
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
44
|
+
__webpack_require__.n = (module) => {
|
|
45
|
+
var getter = module && module.__esModule ?
|
|
46
|
+
() => (module['default']) :
|
|
47
|
+
() => (module);
|
|
48
|
+
__webpack_require__.d(getter, { a: getter });
|
|
49
|
+
return getter;
|
|
76
50
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
51
|
+
|
|
52
|
+
})();
|
|
53
|
+
// webpack/runtime/define_property_getters
|
|
54
|
+
(() => {
|
|
55
|
+
__webpack_require__.d = (exports, definition) => {
|
|
56
|
+
for(var key in definition) {
|
|
57
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
58
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
85
59
|
}
|
|
86
60
|
}
|
|
87
|
-
return splitChunks;
|
|
88
|
-
}
|
|
89
|
-
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
90
|
-
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
91
|
-
const external_path_namespaceObject = require("path");
|
|
92
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
93
|
-
const DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
94
|
-
const CALL_NAME_MAP = {
|
|
95
|
-
RSPRESS: 'rspress',
|
|
96
|
-
RSLIB: 'rslib'
|
|
97
61
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
62
|
+
})();
|
|
63
|
+
// webpack/runtime/has_own_property
|
|
64
|
+
(() => {
|
|
65
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
66
|
+
})();
|
|
67
|
+
// webpack/runtime/make_namespace_object
|
|
68
|
+
(() => {
|
|
69
|
+
// define __esModule on exports
|
|
70
|
+
__webpack_require__.r = (exports) => {
|
|
71
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
72
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
73
|
+
}
|
|
74
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
104
75
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
|
|
126
|
-
if (dataFetchKey && external_fs_extra_default().existsSync(dataFetchClientPath)) exposes[`${dataFetchKey}${DATA_FETCH_CLIENT_SUFFIX}`] = addExcludeDtsSuffix(tempFile);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function mergeStats(browserStats, nodeStats) {
|
|
130
|
-
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
131
|
-
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
132
|
-
if ('publicPath' in browserStats.metaData) browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
133
|
-
return browserStats;
|
|
134
|
-
}
|
|
135
|
-
function mergeManifest(browserManifest, nodeManifest) {
|
|
136
|
-
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
137
|
-
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
138
|
-
if ('publicPath' in browserManifest.metaData) browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
139
|
-
return browserManifest;
|
|
140
|
-
}
|
|
141
|
-
function mergeStatsAndManifest(nodeAssets, browserAssets) {
|
|
142
|
-
const { stats: browserStats, manifest: browserManifest } = browserAssets;
|
|
143
|
-
const { stats: nodeStats, manifest: nodeManifest } = nodeAssets;
|
|
144
|
-
if (!browserStats || !nodeStats || !browserManifest || !nodeManifest) throw new Error('Failed to read stats or manifest assets for merge');
|
|
145
|
-
const mergedStats = mergeStats(browserStats.data, nodeStats.data);
|
|
146
|
-
const mergedManifest = mergeManifest(browserManifest.data, nodeManifest.data);
|
|
147
|
-
return {
|
|
148
|
-
mergedStats: mergedStats,
|
|
149
|
-
mergedStatsFilePath: browserStats.filename,
|
|
150
|
-
mergedManifest: mergedManifest,
|
|
151
|
-
mergedManifestFilePath: browserManifest.filename
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function updateStatsAndManifest(nodeAssets, browserAssets, outputDir) {
|
|
155
|
-
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodeAssets, browserAssets);
|
|
156
|
-
external_fs_extra_default().writeFileSync(external_path_default().resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
157
|
-
external_fs_extra_default().writeFileSync(external_path_default().resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
158
|
-
}
|
|
159
|
-
const external_node_module_namespaceObject = require("node:module");
|
|
160
|
-
const ssr_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
161
|
-
const resolve = ssr_require.resolve;
|
|
162
|
-
const SSR_DIR = 'ssr';
|
|
163
|
-
const SSR_ENV_NAME = 'mf-ssr';
|
|
164
|
-
const ENV_NAME = 'mf';
|
|
165
|
-
function setSSREnv() {
|
|
166
|
-
process.env['MF_SSR_PRJ'] = 'true';
|
|
167
|
-
}
|
|
168
|
-
const isDev = ()=>'development' === process.env['NODE_ENV'];
|
|
169
|
-
function patchNodeConfig(config, mfConfig) {
|
|
170
|
-
var _config_output;
|
|
171
|
-
config.output ||= {};
|
|
172
|
-
config.target = 'async-node';
|
|
173
|
-
const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
174
|
-
config.plugins ||= [];
|
|
175
|
-
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
176
|
-
const uniqueName = mfConfig.name || (null == (_config_output = config.output) ? void 0 : _config_output.uniqueName);
|
|
177
|
-
const chunkFileName = config.output.chunkFilename;
|
|
178
|
-
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
179
|
-
const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
|
|
180
|
-
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
|
|
184
|
-
config.output ||= {};
|
|
185
|
-
if (modifyPublicPath) {
|
|
186
|
-
var _config_output;
|
|
187
|
-
if ('string' != typeof (null == (_config_output = config.output) ? void 0 : _config_output.publicPath)) throw new Error('publicPath must be string!');
|
|
188
|
-
const publicPath = config.output.publicPath;
|
|
189
|
-
if ('auto' === publicPath) throw new Error('publicPath can not be "auto"!');
|
|
190
|
-
const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
|
|
191
|
-
config.output.publicPath = publicPathWithSSRDir;
|
|
192
|
-
}
|
|
193
|
-
if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) config.entry = 'data:application/node;base64,';
|
|
194
|
-
patchNodeConfig(config, mfConfig);
|
|
195
|
-
return config;
|
|
196
|
-
}
|
|
197
|
-
function patchToolsTspack(envConfig, fn) {
|
|
198
|
-
var _envConfig_tools;
|
|
199
|
-
const rspackArr = [];
|
|
200
|
-
if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
|
|
201
|
-
var _envConfig_tools1, _envConfig_tools2;
|
|
202
|
-
if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
|
|
203
|
-
var _envConfig_tools3;
|
|
204
|
-
rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
|
|
205
|
-
} else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
|
|
206
|
-
var _envConfig_tools4;
|
|
207
|
-
rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
envConfig.tools ||= {};
|
|
211
|
-
envConfig.tools.rspack = [
|
|
212
|
-
...rspackArr,
|
|
213
|
-
fn
|
|
214
|
-
];
|
|
215
|
-
}
|
|
216
|
-
function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
|
|
217
|
-
var _envConfig_tools, _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
|
|
218
|
-
const rspackArr = [];
|
|
219
|
-
if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
|
|
220
|
-
var _envConfig_tools1, _envConfig_tools2;
|
|
221
|
-
if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
|
|
222
|
-
var _envConfig_tools3;
|
|
223
|
-
rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
|
|
224
|
-
} else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
|
|
225
|
-
var _envConfig_tools4;
|
|
226
|
-
rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const ssrEnvConfig = {
|
|
230
|
-
...envConfig
|
|
231
|
-
};
|
|
232
|
-
patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
|
|
233
|
-
if (environment.name !== SSR_ENV_NAME) return;
|
|
234
|
-
patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
|
|
235
|
-
});
|
|
236
|
-
ssrEnvConfig.output = {
|
|
237
|
-
...ssrEnvConfig.output,
|
|
238
|
-
target: 'node',
|
|
239
|
-
distPath: {
|
|
240
|
-
...null == (_ssrEnvConfig_output = ssrEnvConfig.output) ? void 0 : _ssrEnvConfig_output.distPath,
|
|
241
|
-
root: external_path_default().join((null == (_ssrEnvConfig_output1 = ssrEnvConfig.output) ? void 0 : null == (_ssrEnvConfig_output_distPath = _ssrEnvConfig_output1.distPath) ? void 0 : _ssrEnvConfig_output_distPath.root) || (null == (_rsbuildConfig_output = rsbuildConfig.output) ? void 0 : null == (_rsbuildConfig_output_distPath = _rsbuildConfig_output.distPath) ? void 0 : _rsbuildConfig_output_distPath.root) || '', ssrDir)
|
|
242
|
-
},
|
|
243
|
-
emitAssets: true
|
|
244
|
-
};
|
|
245
|
-
return ssrEnvConfig;
|
|
246
|
-
}
|
|
247
|
-
function patchNodeMFConfig(mfConfig) {
|
|
248
|
-
var _mfConfig_library;
|
|
249
|
-
if (mfConfig.remotes) mfConfig.remoteType = "script";
|
|
250
|
-
mfConfig.exposes = {
|
|
251
|
-
...mfConfig.exposes
|
|
252
|
-
};
|
|
253
|
-
mfConfig.library = {
|
|
254
|
-
...mfConfig.library,
|
|
255
|
-
name: mfConfig.name,
|
|
256
|
-
type: (null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
|
|
257
|
-
};
|
|
258
|
-
mfConfig.runtimePlugins = [
|
|
259
|
-
...mfConfig.runtimePlugins || []
|
|
260
|
-
];
|
|
261
|
-
mfConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
|
|
262
|
-
if (isDev()) mfConfig.runtimePlugins.push(resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
263
|
-
}
|
|
264
|
-
function createSSRMFConfig(mfConfig) {
|
|
265
|
-
const ssrMFConfig = {
|
|
266
|
-
...mfConfig
|
|
267
|
-
};
|
|
268
|
-
patchNodeMFConfig(ssrMFConfig);
|
|
269
|
-
ssrMFConfig.dts = false;
|
|
270
|
-
ssrMFConfig.dev = false;
|
|
271
|
-
return ssrMFConfig;
|
|
272
|
-
}
|
|
273
|
-
function isRegExp(target) {
|
|
274
|
-
return external_util_default().types.isRegExp(target);
|
|
275
|
-
}
|
|
276
|
-
const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
277
|
-
const RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
|
|
278
|
-
const LIB_FORMAT = [
|
|
279
|
-
'umd',
|
|
280
|
-
'modern-module'
|
|
281
|
-
];
|
|
282
|
-
const DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
|
|
283
|
-
function isStoryBook(rsbuildConfig) {
|
|
284
|
-
var _rsbuildConfig_plugins;
|
|
285
|
-
if (null == (_rsbuildConfig_plugins = rsbuildConfig.plugins) ? void 0 : _rsbuildConfig_plugins.find((p)=>p && 'name' in p && 'module-federation-storybook-plugin' === p.name)) return true;
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
function isMFFormat(bundlerConfig) {
|
|
289
|
-
var _bundlerConfig_output;
|
|
290
|
-
const library = null == (_bundlerConfig_output = bundlerConfig.output) ? void 0 : _bundlerConfig_output.library;
|
|
291
|
-
if (bundlerConfig.name === SSR_ENV_NAME) return true;
|
|
292
|
-
return !('object' == typeof library && !Array.isArray(library) && 'type' in library && (LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
76
|
+
})();
|
|
77
|
+
/************************************************************************/
|
|
78
|
+
var __webpack_exports__ = {};
|
|
79
|
+
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
80
|
+
(() => {
|
|
81
|
+
__webpack_require__.r(__webpack_exports__);
|
|
82
|
+
/* ESM import */var _cli_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./cli/index");
|
|
83
|
+
/* ESM import */var _cli_index__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cli_index__WEBPACK_IMPORTED_MODULE_0__);
|
|
84
|
+
|
|
85
|
+
/* ESM reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
86
|
+
/* ESM reexport (unknown) */ for( var __WEBPACK_IMPORT_KEY__ in _cli_index__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] =function(key) { return _cli_index__WEBPACK_IMPORTED_MODULE_0__[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)
|
|
87
|
+
/* ESM reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
})();
|
|
91
|
+
|
|
92
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
93
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
293
94
|
}
|
|
294
|
-
|
|
295
|
-
const isRspressSSGConfig = (bundlerConfigName)=>"node" === bundlerConfigName;
|
|
296
|
-
const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
297
|
-
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
298
|
-
setup: (api)=>{
|
|
299
|
-
const { target = 'web', ssr, ssrDir = SSR_DIR, environment = DEFAULT_MF_ENVIRONMENT_NAME } = rsbuildOptions || {};
|
|
300
|
-
if (ssr) throw new Error("The `ssr` option is deprecated. If you want to enable SSR, please use `target: 'dual'` instead.");
|
|
301
|
-
const { callerName } = api.context;
|
|
302
|
-
const originalRsbuildConfig = api.getRsbuildConfig();
|
|
303
|
-
if (!callerName) throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
304
|
-
const isRslib = callerName === CALL_NAME_MAP.RSLIB;
|
|
305
|
-
const isRspress = callerName === CALL_NAME_MAP.RSPRESS;
|
|
306
|
-
const isSSR = 'dual' === target;
|
|
307
|
-
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
308
|
-
var _rsbuildConfig_environments;
|
|
309
|
-
if (!isRslib && !isRspress) throw new Error("'target' option is only supported in Rslib.");
|
|
310
|
-
const rsbuildConfig = api.getRsbuildConfig();
|
|
311
|
-
if (!(null == (_rsbuildConfig_environments = rsbuildConfig.environments) ? void 0 : _rsbuildConfig_environments[environment]) || Object.keys(rsbuildConfig.environments).some((key)=>key.startsWith(environment) && key !== environment)) throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
|
|
312
|
-
setSSREnv();
|
|
313
|
-
}
|
|
314
|
-
const sharedOptions = (0, enhanced_namespaceObject.parseOptions)(moduleFederationOptions.shared || [], (item, key)=>{
|
|
315
|
-
if ('string' != typeof item) throw new Error('Unexpected array in shared');
|
|
316
|
-
const config = item !== key && (0, sdk_namespaceObject.isRequiredVersion)(item) ? {
|
|
317
|
-
import: key,
|
|
318
|
-
requiredVersion: item
|
|
319
|
-
} : {
|
|
320
|
-
import: item
|
|
321
|
-
};
|
|
322
|
-
return config;
|
|
323
|
-
}, (item)=>item);
|
|
324
|
-
const shared = sharedOptions.map((shared)=>shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0]);
|
|
325
|
-
api.modifyRsbuildConfig((config)=>{
|
|
326
|
-
if (isStoryBook(config)) return;
|
|
327
|
-
if (moduleFederationOptions.exposes) {
|
|
328
|
-
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
329
|
-
config.dev ||= {};
|
|
330
|
-
config.server ||= {};
|
|
331
|
-
const userConfig = api.getRsbuildConfig('original');
|
|
332
|
-
config.server.headers ||= {};
|
|
333
|
-
if (!config.server.headers['Access-Control-Allow-Origin'] && !('object' == typeof (null == (_userConfig_server = userConfig.server) ? void 0 : _userConfig_server.cors) && userConfig.server.cors.origin)) {
|
|
334
|
-
const corsWarnMsgs = [
|
|
335
|
-
'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.',
|
|
336
|
-
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
337
|
-
];
|
|
338
|
-
isRslib || isRspress || src_logger.warn(corsWarnMsgs.join('\n'));
|
|
339
|
-
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
340
|
-
}
|
|
341
|
-
if ((null == (_config_server = config.server) ? void 0 : _config_server.port) && !(null == (_config_dev_client = config.dev.client) ? void 0 : _config_dev_client.port)) {
|
|
342
|
-
config.dev.client ||= {};
|
|
343
|
-
config.dev.client.port = config.server.port;
|
|
344
|
-
}
|
|
345
|
-
const originalConfig = api.getRsbuildConfig('original');
|
|
346
|
-
if ((null == (_originalConfig_dev = originalConfig.dev) ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null == (_config_server1 = config.server) ? void 0 : _config_server1.base)) config.dev.assetPrefix = true;
|
|
347
|
-
}
|
|
348
|
-
if (isSSR) {
|
|
349
|
-
var _config_environments, _config_environments1;
|
|
350
|
-
if (null == (_config_environments = config.environments) ? void 0 : _config_environments[SSR_ENV_NAME]) throw new Error(`'${SSR_ENV_NAME}' environment is already defined.Please use another name.`);
|
|
351
|
-
config.environments[SSR_ENV_NAME] = createSSRREnvConfig(null == (_config_environments1 = config.environments) ? void 0 : _config_environments1[environment], moduleFederationOptions, ssrDir, config, callerName);
|
|
352
|
-
} else if ('node' === target) {
|
|
353
|
-
const mfEnv = config.environments[ENV_NAME];
|
|
354
|
-
patchToolsTspack(mfEnv, (config, { environment })=>{
|
|
355
|
-
config.target = 'async-node';
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
api.modifyEnvironmentConfig((config)=>{
|
|
360
|
-
config.source.include = [
|
|
361
|
-
...config.source.include || [],
|
|
362
|
-
/@module-federation[\\/]/
|
|
363
|
-
];
|
|
364
|
-
return config;
|
|
365
|
-
});
|
|
366
|
-
const generateMergedStatsAndManifestOptions = {
|
|
367
|
-
options: {
|
|
368
|
-
nodePlugin: void 0,
|
|
369
|
-
browserPlugin: void 0,
|
|
370
|
-
rspressSSGPlugin: void 0,
|
|
371
|
-
distOutputDir: void 0,
|
|
372
|
-
browserEnvironmentName: void 0,
|
|
373
|
-
nodeEnvironmentName: void 0
|
|
374
|
-
},
|
|
375
|
-
assetResources: {},
|
|
376
|
-
isSSRConfig,
|
|
377
|
-
isRspressSSGConfig
|
|
378
|
-
};
|
|
379
|
-
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
380
|
-
const defaultBrowserEnvironmentName = environment;
|
|
381
|
-
const assetFileNames = (0, sdk_namespaceObject.getManifestFileName)(moduleFederationOptions.manifest);
|
|
382
|
-
if (false !== moduleFederationOptions.manifest) api.processAssets({
|
|
383
|
-
stage: 'report'
|
|
384
|
-
}, ({ assets, environment: envContext })=>{
|
|
385
|
-
const expectedBrowserEnv = generateMergedStatsAndManifestOptions.options.browserEnvironmentName ?? defaultBrowserEnvironmentName;
|
|
386
|
-
const expectedNodeEnv = generateMergedStatsAndManifestOptions.options.nodeEnvironmentName ?? SSR_ENV_NAME;
|
|
387
|
-
const envName = envContext.name;
|
|
388
|
-
if (envName !== expectedBrowserEnv && envName !== expectedNodeEnv) return;
|
|
389
|
-
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
390
|
-
const targetResources = assetResources[envName] || (assetResources[envName] = {});
|
|
391
|
-
const statsAsset = assets[assetFileNames.statsFileName];
|
|
392
|
-
if (statsAsset) try {
|
|
393
|
-
const raw = statsAsset.source();
|
|
394
|
-
const content = 'string' == typeof raw ? raw : raw.toString();
|
|
395
|
-
targetResources.stats = {
|
|
396
|
-
data: JSON.parse(content),
|
|
397
|
-
filename: assetFileNames.statsFileName
|
|
398
|
-
};
|
|
399
|
-
} catch (err) {
|
|
400
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
401
|
-
src_logger.error(`Failed to parse stats asset "${assetFileNames.statsFileName}" for environment "${envName}": ${message} `);
|
|
402
|
-
}
|
|
403
|
-
const manifestAsset = assets[assetFileNames.manifestFileName];
|
|
404
|
-
if (manifestAsset) try {
|
|
405
|
-
const raw = manifestAsset.source();
|
|
406
|
-
const content = 'string' == typeof raw ? raw : raw.toString();
|
|
407
|
-
targetResources.manifest = {
|
|
408
|
-
data: JSON.parse(content),
|
|
409
|
-
filename: assetFileNames.manifestFileName
|
|
410
|
-
};
|
|
411
|
-
} catch (err) {
|
|
412
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
413
|
-
src_logger.error(`Failed to parse manifest asset "${assetFileNames.manifestFileName}" for environment "${envName}": ${message} `);
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
|
|
417
|
-
if (!bundlerConfigs) throw new Error('Can not get bundlerConfigs!');
|
|
418
|
-
bundlerConfigs.forEach((bundlerConfig)=>{
|
|
419
|
-
if (!isMFFormat(bundlerConfig) && !isRspress) return;
|
|
420
|
-
if (isStoryBook(originalRsbuildConfig)) bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
|
|
421
|
-
else {
|
|
422
|
-
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1, _bundlerConfig_output2;
|
|
423
|
-
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, null == bundlerConfig ? void 0 : null == (_bundlerConfig_optimization = bundlerConfig.optimization) ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
424
|
-
addDataFetchExposes(moduleFederationOptions.exposes, isSSRConfig(bundlerConfig.name));
|
|
425
|
-
null == (_bundlerConfig_optimization1 = bundlerConfig.optimization) || delete _bundlerConfig_optimization1.runtimeChunk;
|
|
426
|
-
const externals = bundlerConfig.externals;
|
|
427
|
-
if (Array.isArray(externals)) {
|
|
428
|
-
const sharedModules = new Set();
|
|
429
|
-
bundlerConfig.externals = externals.filter((ext)=>{
|
|
430
|
-
let sharedModule;
|
|
431
|
-
if (isRegExp(ext)) {
|
|
432
|
-
const match = shared.some((dep)=>{
|
|
433
|
-
if (ext.test(dep) || ext.test(package_namespaceObject.UU)) {
|
|
434
|
-
sharedModule = dep;
|
|
435
|
-
return true;
|
|
436
|
-
}
|
|
437
|
-
return false;
|
|
438
|
-
});
|
|
439
|
-
match && sharedModule && sharedModules.add(sharedModule);
|
|
440
|
-
return !match;
|
|
441
|
-
}
|
|
442
|
-
if ('string' == typeof ext) {
|
|
443
|
-
if (ext === package_namespaceObject.UU) return false;
|
|
444
|
-
const match = shared.some((dep)=>{
|
|
445
|
-
if (dep === ext) sharedModule = dep;
|
|
446
|
-
return dep === ext;
|
|
447
|
-
});
|
|
448
|
-
if (match) {
|
|
449
|
-
sharedModule && sharedModules.add(sharedModule);
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return true;
|
|
454
|
-
});
|
|
455
|
-
if (sharedModules.size > 0) for (const sharedModule of sharedModules)src_logger.log(`${sharedModule} is removed from externals because it is a shared module.`);
|
|
456
|
-
}
|
|
457
|
-
if (!(null == (_bundlerConfig_output = bundlerConfig.output) ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !isSSRConfig(bundlerConfig.name) && !isRspressSSGConfig(bundlerConfig.name) && 'node' !== target) {
|
|
458
|
-
bundlerConfig.output.chunkLoading = 'jsonp';
|
|
459
|
-
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name} `;
|
|
460
|
-
}
|
|
461
|
-
if ('node' === target && isMFFormat(bundlerConfig)) {
|
|
462
|
-
patchNodeConfig(bundlerConfig, moduleFederationOptions);
|
|
463
|
-
patchNodeMFConfig(moduleFederationOptions);
|
|
464
|
-
}
|
|
465
|
-
if (!(null == (_bundlerConfig_output1 = bundlerConfig.output) ? void 0 : _bundlerConfig_output1.uniqueName)) bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
466
|
-
if ((null == (_bundlerConfig_output2 = bundlerConfig.output) ? void 0 : _bundlerConfig_output2.publicPath) === void 0 && !isSSRConfig(bundlerConfig.name) && !isRspressSSGConfig(bundlerConfig.name)) bundlerConfig.output.publicPath = 'auto';
|
|
467
|
-
if (!bundlerConfig.plugins.find((p)=>p && p.name === rspack_namespaceObject.PLUGIN_NAME)) {
|
|
468
|
-
var _bundlerConfig_output3;
|
|
469
|
-
if (isSSRConfig(bundlerConfig.name)) {
|
|
470
|
-
generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack_namespaceObject.ModuleFederationPlugin(createSSRMFConfig(moduleFederationOptions));
|
|
471
|
-
generateMergedStatsAndManifestOptions.options.nodeEnvironmentName = bundlerConfig.name || SSR_ENV_NAME;
|
|
472
|
-
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
if (isRspressSSGConfig(bundlerConfig.name)) {
|
|
476
|
-
const mfConfig = {
|
|
477
|
-
...createSSRMFConfig(moduleFederationOptions),
|
|
478
|
-
exposes: {},
|
|
479
|
-
manifest: false,
|
|
480
|
-
library: void 0
|
|
481
|
-
};
|
|
482
|
-
patchSSRRspackConfig(bundlerConfig, mfConfig, "ssr", callerName, false, false);
|
|
483
|
-
bundlerConfig.output ||= {};
|
|
484
|
-
bundlerConfig.output.publicPath = '/';
|
|
485
|
-
bundlerConfig.output.asyncChunks = void 0;
|
|
486
|
-
generateMergedStatsAndManifestOptions.options.rspressSSGPlugin = new rspack_namespaceObject.ModuleFederationPlugin(mfConfig);
|
|
487
|
-
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.rspressSSGPlugin);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack_namespaceObject.ModuleFederationPlugin(moduleFederationOptions);
|
|
491
|
-
generateMergedStatsAndManifestOptions.options.distOutputDir = (null == (_bundlerConfig_output3 = bundlerConfig.output) ? void 0 : _bundlerConfig_output3.path) || '';
|
|
492
|
-
generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
|
|
493
|
-
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
});
|
|
498
|
-
const generateMergedStatsAndManifest = ()=>{
|
|
499
|
-
const { distOutputDir, browserEnvironmentName, nodeEnvironmentName } = generateMergedStatsAndManifestOptions.options;
|
|
500
|
-
if (!distOutputDir || !browserEnvironmentName || !nodeEnvironmentName) return;
|
|
501
|
-
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
502
|
-
const browserAssets = assetResources[browserEnvironmentName];
|
|
503
|
-
const nodeAssets = assetResources[nodeEnvironmentName];
|
|
504
|
-
if (!browserAssets || !nodeAssets) return;
|
|
505
|
-
try {
|
|
506
|
-
updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
|
|
507
|
-
} catch (err) {
|
|
508
|
-
src_logger.error(err);
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
api.onDevCompileDone(()=>{
|
|
512
|
-
generateMergedStatsAndManifest();
|
|
513
|
-
});
|
|
514
|
-
api.onAfterBuild(()=>{
|
|
515
|
-
generateMergedStatsAndManifest();
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
|
|
520
|
-
exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = __webpack_exports__.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
|
|
521
|
-
exports.SSR_DIR = __webpack_exports__.SSR_DIR;
|
|
522
|
-
exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
|
|
523
|
-
exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
|
|
524
|
-
exports.isMFFormat = __webpack_exports__.isMFFormat;
|
|
525
|
-
exports.pluginModuleFederation = __webpack_exports__.pluginModuleFederation;
|
|
526
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
527
|
-
"PLUGIN_NAME",
|
|
528
|
-
"RSBUILD_PLUGIN_MODULE_FEDERATION_NAME",
|
|
529
|
-
"SSR_DIR",
|
|
530
|
-
"TreeShakingSharedPlugin",
|
|
531
|
-
"createModuleFederationConfig",
|
|
532
|
-
"isMFFormat",
|
|
533
|
-
"pluginModuleFederation"
|
|
534
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
535
|
-
Object.defineProperty(exports, '__esModule', {
|
|
536
|
-
value: true
|
|
537
|
-
});
|
|
95
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|