@module-federation/rsbuild-plugin 0.0.0-perf-devtools-20260108034446 → 0.0.0-perf-website-code-usage-20260914033703

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.
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ // webpack/runtime/compat_get_default_export
13
+ (() => {
14
+ // getDefaultExport function for compatibility with non-ESM modules
15
+ __webpack_require__.n = (module) => {
16
+ var getter = module && module.__esModule ?
17
+ () => (module['default']) :
18
+ () => (module);
19
+ __webpack_require__.d(getter, { a: getter });
20
+ return getter;
21
+ };
22
+
23
+ })();
24
+ // webpack/runtime/define_property_getters
25
+ (() => {
26
+ __webpack_require__.d = (exports, getters, values) => {
27
+ var define = (defs, kind) => {
28
+ for(var key in defs) {
29
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
31
+ }
32
+ }
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ // webpack/runtime/has_own_property
39
+ (() => {
40
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
41
+ })();
42
+ // webpack/runtime/make_namespace_object
43
+ (() => {
44
+ // define __esModule on exports
45
+ __webpack_require__.r = (exports) => {
46
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ }
49
+ Object.defineProperty(exports, '__esModule', { value: true });
50
+ };
51
+ })();
52
+ var __webpack_exports__ = {};
53
+ // ESM COMPAT FLAG
54
+ __webpack_require__.r(__webpack_exports__);
55
+
56
+ // EXPORTS
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ ENV_NAME: () => (/* binding */ ENV_NAME),
59
+ SSR_DIR: () => (/* binding */ SSR_DIR),
60
+ SSR_ENV_NAME: () => (/* binding */ SSR_ENV_NAME),
61
+ createSSRMFConfig: () => (/* binding */ createSSRMFConfig),
62
+ createSSRREnvConfig: () => (/* binding */ createSSRREnvConfig),
63
+ patchNodeConfig: () => (/* binding */ patchNodeConfig),
64
+ patchNodeMFConfig: () => (/* binding */ patchNodeMFConfig),
65
+ patchSSRRspackConfig: () => (/* binding */ patchSSRRspackConfig),
66
+ patchToolsTspack: () => (/* binding */ patchToolsTspack),
67
+ setSSREnv: () => (/* binding */ setSSREnv)
68
+ });
69
+
70
+ ;// CONCATENATED MODULE: external "path"
71
+ const external_path_namespaceObject = require("path");
72
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
73
+ ;// CONCATENATED MODULE: external "node:module"
74
+ const external_node_module_namespaceObject = require("node:module");
75
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
76
+ const sdk_namespaceObject = require("@module-federation/sdk");
77
+ ;// CONCATENATED MODULE: external "../constant.js"
78
+ const external_constant_js_namespaceObject = require("../constant.js");
79
+ ;// CONCATENATED MODULE: ./src/utils/ssr.ts
80
+
81
+
82
+
83
+
84
+ const ssr_require = (0,external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
85
+ const resolve = ssr_require.resolve;
86
+ function resolveOrRequest(request) {
87
+ try {
88
+ return resolve(request);
89
+ } catch {
90
+ return request;
91
+ }
92
+ }
93
+ function safeRequire(request) {
94
+ try {
95
+ return ssr_require(request);
96
+ } catch {
97
+ return undefined;
98
+ }
99
+ }
100
+ const SSR_DIR = 'ssr';
101
+ const SSR_ENV_NAME = 'mf-ssr';
102
+ const ENV_NAME = 'mf';
103
+ function setSSREnv() {
104
+ process.env['MF_SSR_PRJ'] = 'true';
105
+ }
106
+ const isDev = ()=>{
107
+ return process.env['NODE_ENV'] === 'development';
108
+ };
109
+ function patchNodeConfig(config, mfConfig) {
110
+ config.output ||= {};
111
+ if (config.output.publicPath === 'auto') {
112
+ config.output.publicPath = '';
113
+ }
114
+ config.target = 'async-node';
115
+ // Force node federation output to CJS + async chunk loading.
116
+ // This prevents browser jsonp runtime handlers from leaking into SSR remotes.
117
+ config.output.module = false;
118
+ config.output.chunkFormat = 'commonjs';
119
+ config.output.chunkLoading = 'async-node';
120
+ const prevLibrary = config.output.library;
121
+ if (prevLibrary && typeof prevLibrary === 'object' && !Array.isArray(prevLibrary)) {
122
+ config.output.library = {
123
+ ...prevLibrary,
124
+ type: 'commonjs-module'
125
+ };
126
+ } else if (typeof prevLibrary === 'string' || Array.isArray(prevLibrary)) {
127
+ config.output.library = {
128
+ name: prevLibrary,
129
+ type: 'commonjs-module'
130
+ };
131
+ } else {
132
+ config.output.library = {
133
+ type: 'commonjs-module'
134
+ };
135
+ }
136
+ delete config.output.chunkLoadingGlobal;
137
+ const UniverseEntryChunkTrackerPluginModule = safeRequire('@module-federation/node/universe-entry-chunk-tracker-plugin');
138
+ const UniverseEntryChunkTrackerPlugin = UniverseEntryChunkTrackerPluginModule?.default;
139
+ config.plugins ||= [];
140
+ if (isDev() && UniverseEntryChunkTrackerPlugin) {
141
+ config.plugins.push(new UniverseEntryChunkTrackerPlugin());
142
+ }
143
+ const uniqueName = mfConfig.name || config.output?.uniqueName;
144
+ const chunkFileName = config.output.chunkFilename;
145
+ if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
146
+ const encodedName = (0,sdk_namespaceObject.encodeName)(uniqueName);
147
+ config.output.chunkFilename = chunkFileName.endsWith('.js') ? chunkFileName.replace(/\.js$/, `${encodedName}.js`) : `${chunkFileName}${encodedName}`;
148
+ }
149
+ }
150
+ function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
151
+ config.output ||= {};
152
+ if (modifyPublicPath) {
153
+ if (typeof config.output?.publicPath !== 'string') {
154
+ throw new Error('publicPath must be string!');
155
+ }
156
+ const publicPath = config.output.publicPath;
157
+ if (publicPath !== 'auto') {
158
+ const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
159
+ config.output.publicPath = publicPathWithSSRDir;
160
+ }
161
+ }
162
+ if (callerName === external_constant_js_namespaceObject.CALL_NAME_MAP.RSPRESS && resetEntry) {
163
+ // set virtue entry, only need mf entry
164
+ config.entry = 'data:application/node;base64,';
165
+ }
166
+ patchNodeConfig(config, mfConfig);
167
+ return config;
168
+ }
169
+ function patchToolsTspack(envConfig, fn) {
170
+ const rspackArr = [];
171
+ if (envConfig.tools?.rspack) {
172
+ if (Array.isArray(envConfig.tools?.rspack)) {
173
+ rspackArr.push(...envConfig.tools?.rspack);
174
+ } else if (typeof envConfig.tools?.rspack === 'function') {
175
+ rspackArr.push(envConfig.tools?.rspack);
176
+ }
177
+ }
178
+ envConfig.tools ||= {};
179
+ envConfig.tools.rspack = [
180
+ ...rspackArr,
181
+ fn
182
+ ];
183
+ }
184
+ function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
185
+ const rspackArr = [];
186
+ if (envConfig.tools?.rspack) {
187
+ if (Array.isArray(envConfig.tools?.rspack)) {
188
+ rspackArr.push(...envConfig.tools?.rspack);
189
+ } else if (typeof envConfig.tools?.rspack === 'function') {
190
+ rspackArr.push(envConfig.tools?.rspack);
191
+ }
192
+ }
193
+ const ssrEnvConfig = {
194
+ ...envConfig
195
+ };
196
+ patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
197
+ if (environment.name !== SSR_ENV_NAME) {
198
+ return;
199
+ }
200
+ patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
201
+ });
202
+ ssrEnvConfig.output = {
203
+ ...ssrEnvConfig.output,
204
+ // https://rsbuild.rs/config/output/target#other-targets
205
+ // Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
206
+ target: 'node',
207
+ distPath: {
208
+ ...ssrEnvConfig.output?.distPath,
209
+ root: external_path_default().join(ssrEnvConfig.output?.distPath?.root || rsbuildConfig.output?.distPath?.root || '', ssrDir)
210
+ },
211
+ emitAssets: true
212
+ };
213
+ return ssrEnvConfig;
214
+ }
215
+ /**
216
+ * Node-target MF defaults for Rsbuild SSR builds.
217
+ *
218
+ * `@module-federation/rstest` has a sibling helper (`withNodeDefaults` in
219
+ * packages/rstest/src/node-defaults.ts). Both default remotes to script
220
+ * transport and container output to CommonJS. Rstest additionally forces
221
+ * `library.name` to the container name so test workers can resolve it; Rsbuild
222
+ * keeps the bundler-derived name.
223
+ */ function patchNodeMFConfig(mfConfig) {
224
+ if (mfConfig.remotes) {
225
+ mfConfig.remoteType = 'script';
226
+ }
227
+ mfConfig.exposes = {
228
+ ...mfConfig.exposes
229
+ };
230
+ mfConfig.library = {
231
+ ...mfConfig.library,
232
+ type: mfConfig.library?.type ?? 'commonjs-module'
233
+ };
234
+ mfConfig.runtimePlugins = [
235
+ ...mfConfig.runtimePlugins || []
236
+ ];
237
+ mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/runtimePlugin'));
238
+ if (isDev()) {
239
+ mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
240
+ }
241
+ }
242
+ function createSSRMFConfig(mfConfig) {
243
+ const ssrMFConfig = {
244
+ ...mfConfig
245
+ };
246
+ patchNodeMFConfig(ssrMFConfig);
247
+ ssrMFConfig.dts = false;
248
+ ssrMFConfig.dev = false;
249
+ return ssrMFConfig;
250
+ }
251
+
252
+ exports.ENV_NAME = __webpack_exports__.ENV_NAME;
253
+ exports.SSR_DIR = __webpack_exports__.SSR_DIR;
254
+ exports.SSR_ENV_NAME = __webpack_exports__.SSR_ENV_NAME;
255
+ exports.createSSRMFConfig = __webpack_exports__.createSSRMFConfig;
256
+ exports.createSSRREnvConfig = __webpack_exports__.createSSRREnvConfig;
257
+ exports.patchNodeConfig = __webpack_exports__.patchNodeConfig;
258
+ exports.patchNodeMFConfig = __webpack_exports__.patchNodeMFConfig;
259
+ exports.patchSSRRspackConfig = __webpack_exports__.patchSSRRspackConfig;
260
+ exports.patchToolsTspack = __webpack_exports__.patchToolsTspack;
261
+ exports.setSSREnv = __webpack_exports__.setSSREnv;
262
+ for(var __rspack_i in __webpack_exports__) {
263
+ if(["ENV_NAME","SSR_DIR","SSR_ENV_NAME","createSSRMFConfig","createSSRREnvConfig","patchNodeConfig","patchNodeMFConfig","patchSSRRspackConfig","patchToolsTspack","setSSREnv"].indexOf(__rspack_i) === -1) {
264
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
265
+ }
266
+ }
267
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,182 @@
1
+ import path from "path";
2
+ import { createRequire } from "node:module";
3
+ import { encodeName } from "@module-federation/sdk";
4
+ import { CALL_NAME_MAP } from "../constant.mjs";
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ const ssr_require = createRequire(import.meta.url);
15
+ const resolve = ssr_require.resolve;
16
+ function resolveOrRequest(request) {
17
+ try {
18
+ return resolve(request);
19
+ } catch {
20
+ return request;
21
+ }
22
+ }
23
+ function safeRequire(request) {
24
+ try {
25
+ return ssr_require(request);
26
+ } catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ const SSR_DIR = 'ssr';
31
+ const SSR_ENV_NAME = 'mf-ssr';
32
+ const ENV_NAME = 'mf';
33
+ function setSSREnv() {
34
+ process.env['MF_SSR_PRJ'] = 'true';
35
+ }
36
+ const isDev = ()=>{
37
+ return process.env['NODE_ENV'] === 'development';
38
+ };
39
+ function patchNodeConfig(config, mfConfig) {
40
+ config.output ||= {};
41
+ if (config.output.publicPath === 'auto') {
42
+ config.output.publicPath = '';
43
+ }
44
+ config.target = 'async-node';
45
+ // Force node federation output to CJS + async chunk loading.
46
+ // This prevents browser jsonp runtime handlers from leaking into SSR remotes.
47
+ config.output.module = false;
48
+ config.output.chunkFormat = 'commonjs';
49
+ config.output.chunkLoading = 'async-node';
50
+ const prevLibrary = config.output.library;
51
+ if (prevLibrary && typeof prevLibrary === 'object' && !Array.isArray(prevLibrary)) {
52
+ config.output.library = {
53
+ ...prevLibrary,
54
+ type: 'commonjs-module'
55
+ };
56
+ } else if (typeof prevLibrary === 'string' || Array.isArray(prevLibrary)) {
57
+ config.output.library = {
58
+ name: prevLibrary,
59
+ type: 'commonjs-module'
60
+ };
61
+ } else {
62
+ config.output.library = {
63
+ type: 'commonjs-module'
64
+ };
65
+ }
66
+ delete config.output.chunkLoadingGlobal;
67
+ const UniverseEntryChunkTrackerPluginModule = safeRequire('@module-federation/node/universe-entry-chunk-tracker-plugin');
68
+ const UniverseEntryChunkTrackerPlugin = UniverseEntryChunkTrackerPluginModule?.default;
69
+ config.plugins ||= [];
70
+ if (isDev() && UniverseEntryChunkTrackerPlugin) {
71
+ config.plugins.push(new UniverseEntryChunkTrackerPlugin());
72
+ }
73
+ const uniqueName = mfConfig.name || config.output?.uniqueName;
74
+ const chunkFileName = config.output.chunkFilename;
75
+ if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
76
+ const encodedName = encodeName(uniqueName);
77
+ config.output.chunkFilename = chunkFileName.endsWith('.js') ? chunkFileName.replace(/\.js$/, `${encodedName}.js`) : `${chunkFileName}${encodedName}`;
78
+ }
79
+ }
80
+ function patchSSRRspackConfig(config, mfConfig, ssrDir, callerName, resetEntry = true, modifyPublicPath = true) {
81
+ config.output ||= {};
82
+ if (modifyPublicPath) {
83
+ if (typeof config.output?.publicPath !== 'string') {
84
+ throw new Error('publicPath must be string!');
85
+ }
86
+ const publicPath = config.output.publicPath;
87
+ if (publicPath !== 'auto') {
88
+ const publicPathWithSSRDir = `${publicPath}${ssrDir}/`;
89
+ config.output.publicPath = publicPathWithSSRDir;
90
+ }
91
+ }
92
+ if (callerName === CALL_NAME_MAP.RSPRESS && resetEntry) {
93
+ // set virtue entry, only need mf entry
94
+ config.entry = 'data:application/node;base64,';
95
+ }
96
+ patchNodeConfig(config, mfConfig);
97
+ return config;
98
+ }
99
+ function patchToolsTspack(envConfig, fn) {
100
+ const rspackArr = [];
101
+ if (envConfig.tools?.rspack) {
102
+ if (Array.isArray(envConfig.tools?.rspack)) {
103
+ rspackArr.push(...envConfig.tools?.rspack);
104
+ } else if (typeof envConfig.tools?.rspack === 'function') {
105
+ rspackArr.push(envConfig.tools?.rspack);
106
+ }
107
+ }
108
+ envConfig.tools ||= {};
109
+ envConfig.tools.rspack = [
110
+ ...rspackArr,
111
+ fn
112
+ ];
113
+ }
114
+ function createSSRREnvConfig(envConfig, mfConfig, ssrDir, rsbuildConfig, callerName) {
115
+ const rspackArr = [];
116
+ if (envConfig.tools?.rspack) {
117
+ if (Array.isArray(envConfig.tools?.rspack)) {
118
+ rspackArr.push(...envConfig.tools?.rspack);
119
+ } else if (typeof envConfig.tools?.rspack === 'function') {
120
+ rspackArr.push(envConfig.tools?.rspack);
121
+ }
122
+ }
123
+ const ssrEnvConfig = {
124
+ ...envConfig
125
+ };
126
+ patchToolsTspack(ssrEnvConfig, (config, { environment })=>{
127
+ if (environment.name !== SSR_ENV_NAME) {
128
+ return;
129
+ }
130
+ patchSSRRspackConfig(config, mfConfig, ssrDir, callerName);
131
+ });
132
+ ssrEnvConfig.output = {
133
+ ...ssrEnvConfig.output,
134
+ // https://rsbuild.rs/config/output/target#other-targets
135
+ // Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
136
+ target: 'node',
137
+ distPath: {
138
+ ...ssrEnvConfig.output?.distPath,
139
+ root: path.join(ssrEnvConfig.output?.distPath?.root || rsbuildConfig.output?.distPath?.root || '', ssrDir)
140
+ },
141
+ emitAssets: true
142
+ };
143
+ return ssrEnvConfig;
144
+ }
145
+ /**
146
+ * Node-target MF defaults for Rsbuild SSR builds.
147
+ *
148
+ * `@module-federation/rstest` has a sibling helper (`withNodeDefaults` in
149
+ * packages/rstest/src/node-defaults.ts). Both default remotes to script
150
+ * transport and container output to CommonJS. Rstest additionally forces
151
+ * `library.name` to the container name so test workers can resolve it; Rsbuild
152
+ * keeps the bundler-derived name.
153
+ */ function patchNodeMFConfig(mfConfig) {
154
+ if (mfConfig.remotes) {
155
+ mfConfig.remoteType = 'script';
156
+ }
157
+ mfConfig.exposes = {
158
+ ...mfConfig.exposes
159
+ };
160
+ mfConfig.library = {
161
+ ...mfConfig.library,
162
+ type: mfConfig.library?.type ?? 'commonjs-module'
163
+ };
164
+ mfConfig.runtimePlugins = [
165
+ ...mfConfig.runtimePlugins || []
166
+ ];
167
+ mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/runtimePlugin'));
168
+ if (isDev()) {
169
+ mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
170
+ }
171
+ }
172
+ function createSSRMFConfig(mfConfig) {
173
+ const ssrMFConfig = {
174
+ ...mfConfig
175
+ };
176
+ patchNodeMFConfig(ssrMFConfig);
177
+ ssrMFConfig.dts = false;
178
+ ssrMFConfig.dev = false;
179
+ return ssrMFConfig;
180
+ }
181
+
182
+ export { ENV_NAME, SSR_DIR, SSR_ENV_NAME, createSSRMFConfig, createSSRREnvConfig, patchNodeConfig, patchNodeMFConfig, patchSSRRspackConfig, patchToolsTspack, setSSREnv };
@@ -0,0 +1 @@
1
+ export * from './utils/index';