@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/dist/utils.js CHANGED
@@ -1,300 +1,95 @@
1
1
  "use strict";
2
- const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
- }();
5
- var __webpack_require__ = {};
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
- __webpack_require__.d = (exports1, definition)=>{
17
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
18
- enumerable: true,
19
- get: definition[key]
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
- createSSRREnvConfig: ()=>createSSRREnvConfig,
40
- DEFAULT_ASSET_PREFIX: ()=>"/",
41
- SSR_ENV_NAME: ()=>SSR_ENV_NAME,
42
- autoDeleteSplitChunkCacheGroups: ()=>autoDeleteSplitChunkCacheGroups,
43
- setSSREnv: ()=>setSSREnv,
44
- updateStatsAndManifest: ()=>updateStatsAndManifest,
45
- isRegExp: ()=>isRegExp,
46
- patchSSRRspackConfig: ()=>patchSSRRspackConfig,
47
- SSR_DIR: ()=>SSR_DIR,
48
- createSSRMFConfig: ()=>createSSRMFConfig,
49
- addDataFetchExposes: ()=>addDataFetchExposes
8
+ ;
9
+ var __webpack_modules__ = ({
10
+ "./utils/index": (function (module) {
11
+ module.exports = require("./utils/index.js");
12
+
13
+ }),
14
+
50
15
  });
51
- const external_util_namespaceObject = require("util");
52
- var external_util_default = /*#__PURE__*/ __webpack_require__.n(external_util_namespaceObject);
53
- const SPLIT_CHUNK_MAP = {
54
- REACT: 'react',
55
- ROUTER: 'router',
56
- LODASH: 'lib-lodash',
57
- ANTD: 'lib-antd',
58
- ARCO: 'lib-arco',
59
- SEMI: 'lib-semi',
60
- AXIOS: 'lib-axios'
61
- };
62
- const SHARED_SPLIT_CHUNK_MAP = {
63
- react: SPLIT_CHUNK_MAP.REACT,
64
- 'react-dom': SPLIT_CHUNK_MAP.REACT,
65
- 'react-router': SPLIT_CHUNK_MAP.ROUTER,
66
- 'react-router-dom': SPLIT_CHUNK_MAP.ROUTER,
67
- '@remix-run/router': SPLIT_CHUNK_MAP.ROUTER,
68
- lodash: SPLIT_CHUNK_MAP.LODASH,
69
- 'lodash-es': SPLIT_CHUNK_MAP.LODASH,
70
- antd: SPLIT_CHUNK_MAP.ANTD,
71
- '@arco-design/web-react': SPLIT_CHUNK_MAP.ARCO,
72
- '@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
73
- axios: SPLIT_CHUNK_MAP.AXIOS
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;
74
50
  };
75
- function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
76
- if (!mfConfig.shared) return;
77
- if (!splitChunks || !(null == splitChunks ? void 0 : splitChunks.cacheGroups)) return;
78
- const arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
79
- for (const shared of arrayShared){
80
- const splitChunkKey = SHARED_SPLIT_CHUNK_MAP[shared];
81
- if (splitChunkKey) {
82
- if (splitChunks.cacheGroups[splitChunkKey]) delete splitChunks.cacheGroups[splitChunkKey];
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] });
83
59
  }
84
60
  }
85
- return splitChunks;
86
- }
87
- const external_fs_extra_namespaceObject = require("fs-extra");
88
- var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
89
- const external_path_namespaceObject = require("path");
90
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
91
- const sdk_namespaceObject = require("@module-federation/sdk");
92
- const DATA_FETCH_CLIENT_SUFFIX = '.client';
93
- const CALL_NAME_MAP = {
94
- RSPRESS: 'rspress',
95
- RSLIB: 'rslib'
96
61
  };
97
- const addDataFetchExpose = (exposes, key, filepath, suffix = '')=>{
98
- if (!external_fs_extra_default().existsSync(filepath)) return false;
99
- const dataFetchKey = '.' === key ? `./data${suffix}` : `${key}.data${suffix}`;
100
- if (exposes[dataFetchKey] && exposes[dataFetchKey] !== filepath) throw new Error(`data fetch key ${dataFetchKey} already exists, please modify this expose key, do not end with 'data' or '${DATA_FETCH_CLIENT_SUFFIX}'`);
101
- exposes[dataFetchKey] = filepath;
102
- return dataFetchKey;
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 });
103
75
  };
104
- const addExcludeDtsSuffix = (filepath)=>`${filepath}?exclude-mf-dts=true`;
105
- function addDataFetchExposes(exposes, isServer) {
106
- if ('object' != typeof exposes || Array.isArray(exposes)) return;
107
- if (0 === Object.keys(exposes).length) return;
108
- const tempDataFetch = external_path_default().resolve(process.cwd(), `node_modules/${sdk_namespaceObject.TEMP_DIR}`);
109
- const content = "export const fetchData=()=>{throw new Error('should not be called')};";
110
- external_fs_extra_default().ensureDirSync(tempDataFetch);
111
- Object.keys(exposes).forEach((key, index)=>{
112
- const expose = exposes[key];
113
- if ('string' != typeof expose) return;
114
- const absPath = external_path_default().resolve(process.cwd(), expose);
115
- const dataFetchPath = `${absPath.replace(external_path_default().extname(absPath), '')}.data.ts`;
116
- const dataFetchClientPath = `${absPath.replace(external_path_default().extname(absPath), '')}.data.client.ts`;
117
- const tempFile = external_path_default().join(tempDataFetch, `data-fetch-fallback${index}.ts`);
118
- external_fs_extra_default().writeFileSync(tempFile, content);
119
- const dateFetchClientKey = addDataFetchExpose(exposes, key, dataFetchClientPath, DATA_FETCH_CLIENT_SUFFIX);
120
- if (!isServer && dateFetchClientKey) {
121
- exposes[dateFetchClientKey.replace(DATA_FETCH_CLIENT_SUFFIX, '')] = addExcludeDtsSuffix(tempFile);
122
- return;
123
- }
124
- const dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
125
- if (dataFetchKey && external_fs_extra_default().existsSync(dataFetchClientPath)) exposes[`${dataFetchKey}${DATA_FETCH_CLIENT_SUFFIX}`] = addExcludeDtsSuffix(tempFile);
126
- });
127
- }
128
- function mergeStats(browserStats, nodeStats) {
129
- const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
130
- browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
131
- if ('publicPath' in browserStats.metaData) browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
132
- return browserStats;
133
- }
134
- function mergeManifest(browserManifest, nodeManifest) {
135
- const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
136
- browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
137
- if ('publicPath' in browserManifest.metaData) browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
138
- return browserManifest;
139
- }
140
- function mergeStatsAndManifest(nodeAssets, browserAssets) {
141
- const { stats: browserStats, manifest: browserManifest } = browserAssets;
142
- const { stats: nodeStats, manifest: nodeManifest } = nodeAssets;
143
- if (!browserStats || !nodeStats || !browserManifest || !nodeManifest) throw new Error('Failed to read stats or manifest assets for merge');
144
- const mergedStats = mergeStats(browserStats.data, nodeStats.data);
145
- const mergedManifest = mergeManifest(browserManifest.data, nodeManifest.data);
146
- return {
147
- mergedStats: mergedStats,
148
- mergedStatsFilePath: browserStats.filename,
149
- mergedManifest: mergedManifest,
150
- mergedManifestFilePath: browserManifest.filename
151
- };
152
- }
153
- function updateStatsAndManifest(nodeAssets, browserAssets, outputDir) {
154
- const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodeAssets, browserAssets);
155
- external_fs_extra_default().writeFileSync(external_path_default().resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
156
- external_fs_extra_default().writeFileSync(external_path_default().resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
157
- }
158
- const external_node_module_namespaceObject = require("node:module");
159
- const ssr_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
160
- const resolve = ssr_require.resolve;
161
- const SSR_DIR = 'ssr';
162
- const SSR_ENV_NAME = 'mf-ssr';
163
- function setSSREnv() {
164
- process.env['MF_SSR_PRJ'] = 'true';
165
- }
166
- const isDev = ()=>'development' === process.env['NODE_ENV'];
167
- function patchNodeConfig(config, mfConfig) {
168
- var _config_output;
169
- config.output ||= {};
170
- config.target = 'async-node';
171
- const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
172
- config.plugins ||= [];
173
- isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
174
- const uniqueName = mfConfig.name || (null == (_config_output = config.output) ? void 0 : _config_output.uniqueName);
175
- const chunkFileName = config.output.chunkFilename;
176
- if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
177
- const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
178
- config.output.chunkFilename = chunkFileName.replace('.js', suffix);
179
- }
180
- }
181
- function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
182
- config.output ||= {};
183
- if (modifyPublicPath) {
184
- var _config_output;
185
- if ('string' != typeof (null == (_config_output = config.output) ? void 0 : _config_output.publicPath)) throw new Error('publicPath must be string!');
186
- const publicPath = config.output.publicPath;
187
- if ('auto' === publicPath) throw new Error('publicPath can not be "auto"!');
188
- const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
189
- config.output.publicPath = publicPathWithSSRDir;
190
- }
191
- if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) config.entry = 'data:application/node;base64,';
192
- patchNodeConfig(config, mfConfig);
193
- return config;
194
- }
195
- function patchToolsTspack(envConfig, fn) {
196
- var _envConfig_tools;
197
- const rspackArr = [];
198
- if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
199
- var _envConfig_tools1, _envConfig_tools2;
200
- if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
201
- var _envConfig_tools3;
202
- rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
203
- } else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
204
- var _envConfig_tools4;
205
- rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
206
- }
207
- }
208
- envConfig.tools ||= {};
209
- envConfig.tools.rspack = [
210
- ...rspackArr,
211
- fn
212
- ];
213
- }
214
- function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
215
- var _envConfig_tools, _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
216
- const rspackArr = [];
217
- if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
218
- var _envConfig_tools1, _envConfig_tools2;
219
- if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
220
- var _envConfig_tools3;
221
- rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
222
- } else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
223
- var _envConfig_tools4;
224
- rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
225
- }
226
- }
227
- const ssrEnvConfig = {
228
- ...envConfig
229
- };
230
- patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
231
- if (environment.name !== SSR_ENV_NAME) return;
232
- patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
233
- });
234
- ssrEnvConfig.output = {
235
- ...ssrEnvConfig.output,
236
- target: 'node',
237
- distPath: {
238
- ...null == (_ssrEnvConfig_output = ssrEnvConfig.output) ? void 0 : _ssrEnvConfig_output.distPath,
239
- 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)
240
- },
241
- emitAssets: true
242
- };
243
- return ssrEnvConfig;
244
- }
245
- function patchNodeMFConfig(mfConfig) {
246
- var _mfConfig_library;
247
- if (mfConfig.remotes) mfConfig.remoteType = "script";
248
- mfConfig.exposes = {
249
- ...mfConfig.exposes
250
- };
251
- mfConfig.library = {
252
- ...mfConfig.library,
253
- name: mfConfig.name,
254
- type: (null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
255
- };
256
- mfConfig.runtimePlugins = [
257
- ...mfConfig.runtimePlugins || []
258
- ];
259
- mfConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
260
- if (isDev()) mfConfig.runtimePlugins.push(resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
261
- }
262
- function createSSRMFConfig(mfConfig) {
263
- const ssrMFConfig = {
264
- ...mfConfig
265
- };
266
- patchNodeMFConfig(ssrMFConfig);
267
- ssrMFConfig.dts = false;
268
- ssrMFConfig.dev = false;
269
- return ssrMFConfig;
270
- }
271
- function isRegExp(target) {
272
- return external_util_default().types.isRegExp(target);
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 _utils_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./utils/index");
83
+ /* ESM import */var _utils_index__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_utils_index__WEBPACK_IMPORTED_MODULE_0__);
84
+
85
+ /* ESM reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
86
+ /* ESM reexport (unknown) */ for( var __WEBPACK_IMPORT_KEY__ in _utils_index__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] =function(key) { return _utils_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__];
273
94
  }
274
- exports.DEFAULT_ASSET_PREFIX = __webpack_exports__.DEFAULT_ASSET_PREFIX;
275
- exports.SSR_DIR = __webpack_exports__.SSR_DIR;
276
- exports.SSR_ENV_NAME = __webpack_exports__.SSR_ENV_NAME;
277
- exports.addDataFetchExposes = __webpack_exports__.addDataFetchExposes;
278
- exports.autoDeleteSplitChunkCacheGroups = __webpack_exports__.autoDeleteSplitChunkCacheGroups;
279
- exports.createSSRMFConfig = __webpack_exports__.createSSRMFConfig;
280
- exports.createSSRREnvConfig = __webpack_exports__.createSSRREnvConfig;
281
- exports.isRegExp = __webpack_exports__.isRegExp;
282
- exports.patchSSRRspackConfig = __webpack_exports__.patchSSRRspackConfig;
283
- exports.setSSREnv = __webpack_exports__.setSSREnv;
284
- exports.updateStatsAndManifest = __webpack_exports__.updateStatsAndManifest;
285
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
286
- "DEFAULT_ASSET_PREFIX",
287
- "SSR_DIR",
288
- "SSR_ENV_NAME",
289
- "addDataFetchExposes",
290
- "autoDeleteSplitChunkCacheGroups",
291
- "createSSRMFConfig",
292
- "createSSRREnvConfig",
293
- "isRegExp",
294
- "patchSSRRspackConfig",
295
- "setSSREnv",
296
- "updateStatsAndManifest"
297
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
298
- Object.defineProperty(exports, '__esModule', {
299
- value: true
300
- });
95
+ Object.defineProperty(exports, '__esModule', { value: true });
package/dist/utils.mjs CHANGED
@@ -1,222 +1,5 @@
1
- import util from "util";
2
- import fs_extra from "fs-extra";
3
- import path from "path";
4
- import { TEMP_DIR, encodeName } from "@module-federation/sdk";
5
- import { createRequire } from "node:module";
6
- const DATA_FETCH_CLIENT_SUFFIX = '.client';
7
- const CALL_NAME_MAP = {
8
- RSPRESS: 'rspress',
9
- RSLIB: 'rslib'
10
- };
11
- const SPLIT_CHUNK_MAP = {
12
- REACT: 'react',
13
- ROUTER: 'router',
14
- LODASH: 'lib-lodash',
15
- ANTD: 'lib-antd',
16
- ARCO: 'lib-arco',
17
- SEMI: 'lib-semi',
18
- AXIOS: 'lib-axios'
19
- };
20
- const SHARED_SPLIT_CHUNK_MAP = {
21
- react: SPLIT_CHUNK_MAP.REACT,
22
- 'react-dom': SPLIT_CHUNK_MAP.REACT,
23
- 'react-router': SPLIT_CHUNK_MAP.ROUTER,
24
- 'react-router-dom': SPLIT_CHUNK_MAP.ROUTER,
25
- '@remix-run/router': SPLIT_CHUNK_MAP.ROUTER,
26
- lodash: SPLIT_CHUNK_MAP.LODASH,
27
- 'lodash-es': SPLIT_CHUNK_MAP.LODASH,
28
- antd: SPLIT_CHUNK_MAP.ANTD,
29
- '@arco-design/web-react': SPLIT_CHUNK_MAP.ARCO,
30
- '@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
31
- axios: SPLIT_CHUNK_MAP.AXIOS
32
- };
33
- function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
34
- if (!mfConfig.shared) return;
35
- if (!splitChunks || !(null == splitChunks ? void 0 : splitChunks.cacheGroups)) return;
36
- const arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
37
- for (const shared of arrayShared){
38
- const splitChunkKey = SHARED_SPLIT_CHUNK_MAP[shared];
39
- if (splitChunkKey) {
40
- if (splitChunks.cacheGroups[splitChunkKey]) delete splitChunks.cacheGroups[splitChunkKey];
41
- }
42
- }
43
- return splitChunks;
44
- }
45
- const addDataFetchExpose = (exposes, key, filepath, suffix = '')=>{
46
- if (!fs_extra.existsSync(filepath)) return false;
47
- const dataFetchKey = '.' === key ? `./data${suffix}` : `${key}.data${suffix}`;
48
- if (exposes[dataFetchKey] && exposes[dataFetchKey] !== filepath) throw new Error(`data fetch key ${dataFetchKey} already exists, please modify this expose key, do not end with 'data' or '${DATA_FETCH_CLIENT_SUFFIX}'`);
49
- exposes[dataFetchKey] = filepath;
50
- return dataFetchKey;
51
- };
52
- const addExcludeDtsSuffix = (filepath)=>`${filepath}?exclude-mf-dts=true`;
53
- function addDataFetchExposes(exposes, isServer) {
54
- if ('object' != typeof exposes || Array.isArray(exposes)) return;
55
- if (0 === Object.keys(exposes).length) return;
56
- const tempDataFetch = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);
57
- const content = "export const fetchData=()=>{throw new Error('should not be called')};";
58
- fs_extra.ensureDirSync(tempDataFetch);
59
- Object.keys(exposes).forEach((key, index)=>{
60
- const expose = exposes[key];
61
- if ('string' != typeof expose) return;
62
- const absPath = path.resolve(process.cwd(), expose);
63
- const dataFetchPath = `${absPath.replace(path.extname(absPath), '')}.data.ts`;
64
- const dataFetchClientPath = `${absPath.replace(path.extname(absPath), '')}.data.client.ts`;
65
- const tempFile = path.join(tempDataFetch, `data-fetch-fallback${index}.ts`);
66
- fs_extra.writeFileSync(tempFile, content);
67
- const dateFetchClientKey = addDataFetchExpose(exposes, key, dataFetchClientPath, DATA_FETCH_CLIENT_SUFFIX);
68
- if (!isServer && dateFetchClientKey) {
69
- exposes[dateFetchClientKey.replace(DATA_FETCH_CLIENT_SUFFIX, '')] = addExcludeDtsSuffix(tempFile);
70
- return;
71
- }
72
- const dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
73
- if (dataFetchKey && fs_extra.existsSync(dataFetchClientPath)) exposes[`${dataFetchKey}${DATA_FETCH_CLIENT_SUFFIX}`] = addExcludeDtsSuffix(tempFile);
74
- });
75
- }
76
- function mergeStats(browserStats, nodeStats) {
77
- const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
78
- browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
79
- if ('publicPath' in browserStats.metaData) browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
80
- return browserStats;
81
- }
82
- function mergeManifest(browserManifest, nodeManifest) {
83
- const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
84
- browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
85
- if ('publicPath' in browserManifest.metaData) browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
86
- return browserManifest;
87
- }
88
- function mergeStatsAndManifest(nodeAssets, browserAssets) {
89
- const { stats: browserStats, manifest: browserManifest } = browserAssets;
90
- const { stats: nodeStats, manifest: nodeManifest } = nodeAssets;
91
- if (!browserStats || !nodeStats || !browserManifest || !nodeManifest) throw new Error('Failed to read stats or manifest assets for merge');
92
- const mergedStats = mergeStats(browserStats.data, nodeStats.data);
93
- const mergedManifest = mergeManifest(browserManifest.data, nodeManifest.data);
94
- return {
95
- mergedStats: mergedStats,
96
- mergedStatsFilePath: browserStats.filename,
97
- mergedManifest: mergedManifest,
98
- mergedManifestFilePath: browserManifest.filename
99
- };
100
- }
101
- function updateStatsAndManifest(nodeAssets, browserAssets, outputDir) {
102
- const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodeAssets, browserAssets);
103
- fs_extra.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
104
- fs_extra.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
105
- }
106
- const ssr_require = createRequire(import.meta.url);
107
- const resolve = ssr_require.resolve;
108
- const SSR_DIR = 'ssr';
109
- const SSR_ENV_NAME = 'mf-ssr';
110
- function setSSREnv() {
111
- process.env['MF_SSR_PRJ'] = 'true';
112
- }
113
- const isDev = ()=>'development' === process.env['NODE_ENV'];
114
- function patchNodeConfig(config, mfConfig) {
115
- var _config_output;
116
- config.output ||= {};
117
- config.target = 'async-node';
118
- const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
119
- config.plugins ||= [];
120
- isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
121
- const uniqueName = mfConfig.name || (null == (_config_output = config.output) ? void 0 : _config_output.uniqueName);
122
- const chunkFileName = config.output.chunkFilename;
123
- if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
124
- const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
125
- config.output.chunkFilename = chunkFileName.replace('.js', suffix);
126
- }
127
- }
128
- function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
129
- config.output ||= {};
130
- if (modifyPublicPath) {
131
- var _config_output;
132
- if ('string' != typeof (null == (_config_output = config.output) ? void 0 : _config_output.publicPath)) throw new Error('publicPath must be string!');
133
- const publicPath = config.output.publicPath;
134
- if ('auto' === publicPath) throw new Error('publicPath can not be "auto"!');
135
- const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
136
- config.output.publicPath = publicPathWithSSRDir;
137
- }
138
- if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) config.entry = 'data:application/node;base64,';
139
- patchNodeConfig(config, mfConfig);
140
- return config;
141
- }
142
- function patchToolsTspack(envConfig, fn) {
143
- var _envConfig_tools;
144
- const rspackArr = [];
145
- if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
146
- var _envConfig_tools1, _envConfig_tools2;
147
- if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
148
- var _envConfig_tools3;
149
- rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
150
- } else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
151
- var _envConfig_tools4;
152
- rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
153
- }
154
- }
155
- envConfig.tools ||= {};
156
- envConfig.tools.rspack = [
157
- ...rspackArr,
158
- fn
159
- ];
160
- }
161
- function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
162
- var _envConfig_tools, _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
163
- const rspackArr = [];
164
- if (null == (_envConfig_tools = envConfig.tools) ? void 0 : _envConfig_tools.rspack) {
165
- var _envConfig_tools1, _envConfig_tools2;
166
- if (Array.isArray(null == (_envConfig_tools1 = envConfig.tools) ? void 0 : _envConfig_tools1.rspack)) {
167
- var _envConfig_tools3;
168
- rspackArr.push(...null == (_envConfig_tools3 = envConfig.tools) ? void 0 : _envConfig_tools3.rspack);
169
- } else if ('function' == typeof (null == (_envConfig_tools2 = envConfig.tools) ? void 0 : _envConfig_tools2.rspack)) {
170
- var _envConfig_tools4;
171
- rspackArr.push(null == (_envConfig_tools4 = envConfig.tools) ? void 0 : _envConfig_tools4.rspack);
172
- }
173
- }
174
- const ssrEnvConfig = {
175
- ...envConfig
176
- };
177
- patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
178
- if (environment.name !== SSR_ENV_NAME) return;
179
- patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
180
- });
181
- ssrEnvConfig.output = {
182
- ...ssrEnvConfig.output,
183
- target: 'node',
184
- distPath: {
185
- ...null == (_ssrEnvConfig_output = ssrEnvConfig.output) ? void 0 : _ssrEnvConfig_output.distPath,
186
- root: path.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)
187
- },
188
- emitAssets: true
189
- };
190
- return ssrEnvConfig;
191
- }
192
- function patchNodeMFConfig(mfConfig) {
193
- var _mfConfig_library;
194
- if (mfConfig.remotes) mfConfig.remoteType = "script";
195
- mfConfig.exposes = {
196
- ...mfConfig.exposes
197
- };
198
- mfConfig.library = {
199
- ...mfConfig.library,
200
- name: mfConfig.name,
201
- type: (null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
202
- };
203
- mfConfig.runtimePlugins = [
204
- ...mfConfig.runtimePlugins || []
205
- ];
206
- mfConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
207
- if (isDev()) mfConfig.runtimePlugins.push(resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
208
- }
209
- function createSSRMFConfig(mfConfig) {
210
- const ssrMFConfig = {
211
- ...mfConfig
212
- };
213
- patchNodeMFConfig(ssrMFConfig);
214
- ssrMFConfig.dts = false;
215
- ssrMFConfig.dev = false;
216
- return ssrMFConfig;
217
- }
218
- function isRegExp(target) {
219
- return util.types.isRegExp(target);
220
- }
221
- var __webpack_exports__DEFAULT_ASSET_PREFIX = "/";
222
- export { SSR_DIR, SSR_ENV_NAME, addDataFetchExposes, autoDeleteSplitChunkCacheGroups, createSSRMFConfig, createSSRREnvConfig, isRegExp, patchSSRRspackConfig, setSSREnv, updateStatsAndManifest, __webpack_exports__DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX };
1
+ export * from "./utils/index.mjs";
2
+
3
+ ;// CONCATENATED MODULE: ./src/utils.ts
4
+
5
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/rsbuild-plugin",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Module Federation plugin for Rsbuild",
5
5
  "homepage": "https://module-federation.io",
6
6
  "bugs": {
@@ -50,9 +50,9 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "fs-extra": "11.3.0",
53
- "@module-federation/node": "2.7.31",
54
- "@module-federation/enhanced": "2.0.0",
55
- "@module-federation/sdk": "2.0.0"
53
+ "@module-federation/sdk": "2.0.1",
54
+ "@module-federation/enhanced": "2.0.1",
55
+ "@module-federation/node": "2.7.32"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@rslib/core": "^0.12.4",