@module-federation/rsbuild-plugin 0.0.0-next-20250926024003 → 0.0.0-perf-devtools-20260106124142
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/{src/cli → cli}/index.d.ts +4 -1
- package/dist/constant.d.ts +9 -1
- package/dist/constant.js +59 -0
- package/dist/constant.mjs +10 -0
- package/dist/index.js +486 -0
- package/dist/index.mjs +422 -0
- package/dist/{src/utils → utils}/index.d.ts +1 -0
- package/dist/utils/manifest.d.ts +11 -0
- package/dist/{src/utils → utils}/ssr.d.ts +2 -1
- package/dist/utils.js +264 -0
- package/dist/utils.mjs +186 -0
- package/package.json +18 -17
- package/dist/constant.cjs.js +0 -19
- package/dist/constant.cjs.js.map +0 -1
- package/dist/constant.esm.d.ts +0 -1
- package/dist/constant.esm.mjs +0 -12
- package/dist/constant.esm.mjs.map +0 -1
- package/dist/index.cjs.js +0 -360
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.d.ts +0 -1
- package/dist/index.esm.mjs +0 -349
- package/dist/index.esm.mjs.map +0 -1
- package/dist/src/constant.d.ts +0 -9
- package/dist/src/utils/manifest.d.ts +0 -5
- package/dist/utils.cjs.js +0 -329
- package/dist/utils.cjs.js.map +0 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.esm.d.ts +0 -1
- package/dist/utils.esm.mjs +0 -317
- package/dist/utils.esm.mjs.map +0 -1
- /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
- /package/dist/{src/utils → utils}/addDataFetchExposes.d.ts +0 -0
- /package/dist/{src/utils → utils}/autoDeleteSplitChunkCacheGroups.d.ts +0 -0
package/dist/utils.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
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
|
+
};
|
|
14
|
+
})();
|
|
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
|
|
50
|
+
});
|
|
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
|
|
74
|
+
};
|
|
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];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
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
|
+
};
|
|
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;
|
|
103
|
+
};
|
|
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 patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
|
|
168
|
+
var _config_output;
|
|
169
|
+
config.output ||= {};
|
|
170
|
+
if (modifyPublicPath) {
|
|
171
|
+
var _config_output1;
|
|
172
|
+
if ('string' != typeof (null == (_config_output1 = config.output) ? void 0 : _config_output1.publicPath)) throw new Error('publicPath must be string!');
|
|
173
|
+
const publicPath = config.output.publicPath;
|
|
174
|
+
if ('auto' === publicPath) throw new Error('publicPath can not be "auto"!');
|
|
175
|
+
const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
|
|
176
|
+
config.output.publicPath = publicPathWithSSRDir;
|
|
177
|
+
}
|
|
178
|
+
if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) config.entry = 'data:application/node;base64,';
|
|
179
|
+
config.target = 'async-node';
|
|
180
|
+
const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
181
|
+
config.plugins ||= [];
|
|
182
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
183
|
+
const uniqueName = mfConfig.name || (null == (_config_output = config.output) ? void 0 : _config_output.uniqueName);
|
|
184
|
+
const chunkFileName = config.output.chunkFilename;
|
|
185
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
186
|
+
const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
|
|
187
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
188
|
+
}
|
|
189
|
+
return config;
|
|
190
|
+
}
|
|
191
|
+
function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
|
|
192
|
+
var _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
|
|
193
|
+
const ssrEnvConfig = {
|
|
194
|
+
...envConfig,
|
|
195
|
+
tools: {
|
|
196
|
+
rspack: (config, { environment })=>{
|
|
197
|
+
if (environment.name !== SSR_ENV_NAME) return;
|
|
198
|
+
patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
ssrEnvConfig.output = {
|
|
203
|
+
...ssrEnvConfig.output,
|
|
204
|
+
target: 'node',
|
|
205
|
+
distPath: {
|
|
206
|
+
...null == (_ssrEnvConfig_output = ssrEnvConfig.output) ? void 0 : _ssrEnvConfig_output.distPath,
|
|
207
|
+
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)
|
|
208
|
+
},
|
|
209
|
+
emitAssets: true
|
|
210
|
+
};
|
|
211
|
+
return ssrEnvConfig;
|
|
212
|
+
}
|
|
213
|
+
function createSSRMFConfig(mfConfig) {
|
|
214
|
+
var _mfConfig_library;
|
|
215
|
+
const ssrMFConfig = {
|
|
216
|
+
...mfConfig,
|
|
217
|
+
exposes: {
|
|
218
|
+
...mfConfig.exposes
|
|
219
|
+
},
|
|
220
|
+
library: {
|
|
221
|
+
...mfConfig.library,
|
|
222
|
+
name: mfConfig.name,
|
|
223
|
+
type: (null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
|
|
224
|
+
},
|
|
225
|
+
dts: false,
|
|
226
|
+
dev: false,
|
|
227
|
+
runtimePlugins: [
|
|
228
|
+
...mfConfig.runtimePlugins || []
|
|
229
|
+
]
|
|
230
|
+
};
|
|
231
|
+
ssrMFConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
|
|
232
|
+
if (isDev()) ssrMFConfig.runtimePlugins.push(resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
233
|
+
return ssrMFConfig;
|
|
234
|
+
}
|
|
235
|
+
function isRegExp(target) {
|
|
236
|
+
return external_util_default().types.isRegExp(target);
|
|
237
|
+
}
|
|
238
|
+
exports.DEFAULT_ASSET_PREFIX = __webpack_exports__.DEFAULT_ASSET_PREFIX;
|
|
239
|
+
exports.SSR_DIR = __webpack_exports__.SSR_DIR;
|
|
240
|
+
exports.SSR_ENV_NAME = __webpack_exports__.SSR_ENV_NAME;
|
|
241
|
+
exports.addDataFetchExposes = __webpack_exports__.addDataFetchExposes;
|
|
242
|
+
exports.autoDeleteSplitChunkCacheGroups = __webpack_exports__.autoDeleteSplitChunkCacheGroups;
|
|
243
|
+
exports.createSSRMFConfig = __webpack_exports__.createSSRMFConfig;
|
|
244
|
+
exports.createSSRREnvConfig = __webpack_exports__.createSSRREnvConfig;
|
|
245
|
+
exports.isRegExp = __webpack_exports__.isRegExp;
|
|
246
|
+
exports.patchSSRRspackConfig = __webpack_exports__.patchSSRRspackConfig;
|
|
247
|
+
exports.setSSREnv = __webpack_exports__.setSSREnv;
|
|
248
|
+
exports.updateStatsAndManifest = __webpack_exports__.updateStatsAndManifest;
|
|
249
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
250
|
+
"DEFAULT_ASSET_PREFIX",
|
|
251
|
+
"SSR_DIR",
|
|
252
|
+
"SSR_ENV_NAME",
|
|
253
|
+
"addDataFetchExposes",
|
|
254
|
+
"autoDeleteSplitChunkCacheGroups",
|
|
255
|
+
"createSSRMFConfig",
|
|
256
|
+
"createSSRREnvConfig",
|
|
257
|
+
"isRegExp",
|
|
258
|
+
"patchSSRRspackConfig",
|
|
259
|
+
"setSSREnv",
|
|
260
|
+
"updateStatsAndManifest"
|
|
261
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
262
|
+
Object.defineProperty(exports, '__esModule', {
|
|
263
|
+
value: true
|
|
264
|
+
});
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
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 patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
|
|
115
|
+
var _config_output;
|
|
116
|
+
config.output ||= {};
|
|
117
|
+
if (modifyPublicPath) {
|
|
118
|
+
var _config_output1;
|
|
119
|
+
if ('string' != typeof (null == (_config_output1 = config.output) ? void 0 : _config_output1.publicPath)) throw new Error('publicPath must be string!');
|
|
120
|
+
const publicPath = config.output.publicPath;
|
|
121
|
+
if ('auto' === publicPath) throw new Error('publicPath can not be "auto"!');
|
|
122
|
+
const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
|
|
123
|
+
config.output.publicPath = publicPathWithSSRDir;
|
|
124
|
+
}
|
|
125
|
+
if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) config.entry = 'data:application/node;base64,';
|
|
126
|
+
config.target = 'async-node';
|
|
127
|
+
const UniverseEntryChunkTrackerPlugin = ssr_require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
128
|
+
config.plugins ||= [];
|
|
129
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
130
|
+
const uniqueName = mfConfig.name || (null == (_config_output = config.output) ? void 0 : _config_output.uniqueName);
|
|
131
|
+
const chunkFileName = config.output.chunkFilename;
|
|
132
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
133
|
+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
|
|
134
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
135
|
+
}
|
|
136
|
+
return config;
|
|
137
|
+
}
|
|
138
|
+
function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
|
|
139
|
+
var _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1, _rsbuildConfig_output_distPath, _rsbuildConfig_output;
|
|
140
|
+
const ssrEnvConfig = {
|
|
141
|
+
...envConfig,
|
|
142
|
+
tools: {
|
|
143
|
+
rspack: (config, { environment })=>{
|
|
144
|
+
if (environment.name !== SSR_ENV_NAME) return;
|
|
145
|
+
patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
ssrEnvConfig.output = {
|
|
150
|
+
...ssrEnvConfig.output,
|
|
151
|
+
target: 'node',
|
|
152
|
+
distPath: {
|
|
153
|
+
...null == (_ssrEnvConfig_output = ssrEnvConfig.output) ? void 0 : _ssrEnvConfig_output.distPath,
|
|
154
|
+
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)
|
|
155
|
+
},
|
|
156
|
+
emitAssets: true
|
|
157
|
+
};
|
|
158
|
+
return ssrEnvConfig;
|
|
159
|
+
}
|
|
160
|
+
function createSSRMFConfig(mfConfig) {
|
|
161
|
+
var _mfConfig_library;
|
|
162
|
+
const ssrMFConfig = {
|
|
163
|
+
...mfConfig,
|
|
164
|
+
exposes: {
|
|
165
|
+
...mfConfig.exposes
|
|
166
|
+
},
|
|
167
|
+
library: {
|
|
168
|
+
...mfConfig.library,
|
|
169
|
+
name: mfConfig.name,
|
|
170
|
+
type: (null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) ?? 'commonjs-module'
|
|
171
|
+
},
|
|
172
|
+
dts: false,
|
|
173
|
+
dev: false,
|
|
174
|
+
runtimePlugins: [
|
|
175
|
+
...mfConfig.runtimePlugins || []
|
|
176
|
+
]
|
|
177
|
+
};
|
|
178
|
+
ssrMFConfig.runtimePlugins.push(resolve('@module-federation/node/runtimePlugin'));
|
|
179
|
+
if (isDev()) ssrMFConfig.runtimePlugins.push(resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
180
|
+
return ssrMFConfig;
|
|
181
|
+
}
|
|
182
|
+
function isRegExp(target) {
|
|
183
|
+
return util.types.isRegExp(target);
|
|
184
|
+
}
|
|
185
|
+
var __webpack_exports__DEFAULT_ASSET_PREFIX = "/";
|
|
186
|
+
export { SSR_DIR, SSR_ENV_NAME, addDataFetchExposes, autoDeleteSplitChunkCacheGroups, createSSRMFConfig, createSSRREnvConfig, isRegExp, patchSSRRspackConfig, setSSREnv, updateStatsAndManifest, __webpack_exports__DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/rsbuild-plugin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-perf-devtools-20260106124142",
|
|
4
4
|
"description": "Module Federation plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://module-federation.io",
|
|
6
6
|
"bugs": {
|
|
@@ -14,31 +14,31 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.
|
|
19
|
-
"require": "./dist/index.
|
|
17
|
+
"types": "./dist/cli/index.d.ts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./utils": {
|
|
22
|
-
"types": "./dist/utils.d.ts",
|
|
23
|
-
"import": "./dist/utils.
|
|
24
|
-
"require": "./dist/utils.
|
|
22
|
+
"types": "./dist/utils/index.d.ts",
|
|
23
|
+
"import": "./dist/utils.mjs",
|
|
24
|
+
"require": "./dist/utils.js"
|
|
25
25
|
},
|
|
26
26
|
"./constant": {
|
|
27
27
|
"types": "./dist/constant.d.ts",
|
|
28
|
-
"import": "./dist/constant.
|
|
29
|
-
"require": "./dist/constant.
|
|
28
|
+
"import": "./dist/constant.mjs",
|
|
29
|
+
"require": "./dist/constant.js"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
"main": "./dist/index.
|
|
33
|
-
"module": "./dist/index.
|
|
34
|
-
"types": "./dist/index.d.ts",
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.mjs",
|
|
34
|
+
"types": "./dist/cli/index.d.ts",
|
|
35
35
|
"typesVersions": {
|
|
36
36
|
"*": {
|
|
37
37
|
".": [
|
|
38
|
-
"./dist/index.d.ts"
|
|
38
|
+
"./dist/cli/index.d.ts"
|
|
39
39
|
],
|
|
40
40
|
"utils": [
|
|
41
|
-
"./dist/utils.d.ts"
|
|
41
|
+
"./dist/utils/index.d.ts"
|
|
42
42
|
],
|
|
43
43
|
"constant": [
|
|
44
44
|
"./dist/constant.d.ts"
|
|
@@ -50,11 +50,12 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"fs-extra": "11.3.0",
|
|
53
|
-
"@module-federation/
|
|
54
|
-
"@module-federation/
|
|
55
|
-
"@module-federation/node": "0.0.0-
|
|
53
|
+
"@module-federation/sdk": "0.0.0-perf-devtools-20260106124142",
|
|
54
|
+
"@module-federation/enhanced": "0.0.0-perf-devtools-20260106124142",
|
|
55
|
+
"@module-federation/node": "0.0.0-perf-devtools-20260106124142"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
+
"@rslib/core": "^0.12.4",
|
|
58
59
|
"@rsbuild/core": "^1.3.21"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
package/dist/constant.cjs.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var DEFAULT_ASSET_PREFIX = '/';
|
|
4
|
-
var DATA_FETCH_IDENTIFIER = 'data';
|
|
5
|
-
var DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
6
|
-
var CALL_NAME_MAP = {
|
|
7
|
-
RSPRESS: 'rspress',
|
|
8
|
-
RSLIB: 'rslib'
|
|
9
|
-
};
|
|
10
|
-
var RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
11
|
-
var RSPRESS_SSR_DIR = 'ssr';
|
|
12
|
-
|
|
13
|
-
exports.CALL_NAME_MAP = CALL_NAME_MAP;
|
|
14
|
-
exports.DATA_FETCH_CLIENT_SUFFIX = DATA_FETCH_CLIENT_SUFFIX;
|
|
15
|
-
exports.DATA_FETCH_IDENTIFIER = DATA_FETCH_IDENTIFIER;
|
|
16
|
-
exports.DEFAULT_ASSET_PREFIX = DEFAULT_ASSET_PREFIX;
|
|
17
|
-
exports.RSPRESS_BUNDLER_CONFIG_NAME = RSPRESS_BUNDLER_CONFIG_NAME;
|
|
18
|
-
exports.RSPRESS_SSR_DIR = RSPRESS_SSR_DIR;
|
|
19
|
-
//# sourceMappingURL=constant.cjs.js.map
|
package/dist/constant.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
package/dist/constant.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/constant";
|
package/dist/constant.esm.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
var DEFAULT_ASSET_PREFIX = '/';
|
|
2
|
-
var DATA_FETCH_IDENTIFIER = 'data';
|
|
3
|
-
var DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
4
|
-
var CALL_NAME_MAP = {
|
|
5
|
-
RSPRESS: 'rspress',
|
|
6
|
-
RSLIB: 'rslib'
|
|
7
|
-
};
|
|
8
|
-
var RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
9
|
-
var RSPRESS_SSR_DIR = 'ssr';
|
|
10
|
-
|
|
11
|
-
export { CALL_NAME_MAP, DATA_FETCH_CLIENT_SUFFIX, DATA_FETCH_IDENTIFIER, DEFAULT_ASSET_PREFIX, RSPRESS_BUNDLER_CONFIG_NAME, RSPRESS_SSR_DIR };
|
|
12
|
-
//# sourceMappingURL=constant.esm.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.esm.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|