@module-federation/rsbuild-plugin 0.0.0-chore-bump-node-22-20260710161714
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/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/LICENSE +21 -0
- package/dist/cli/index.d.ts +33 -0
- package/dist/cli/index.js +468 -0
- package/dist/cli/index.mjs +389 -0
- package/dist/constant.d.ts +10 -0
- package/dist/constant.js +76 -0
- package/dist/constant.mjs +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +96 -0
- package/dist/index.mjs +4 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +62 -0
- package/dist/logger.mjs +8 -0
- package/dist/utils/addDataFetchExposes.d.ts +2 -0
- package/dist/utils/addDataFetchExposes.js +130 -0
- package/dist/utils/addDataFetchExposes.mjs +62 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.d.ts +6 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.js +102 -0
- package/dist/utils/autoDeleteSplitChunkCacheGroups.mjs +51 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +111 -0
- package/dist/utils/index.mjs +24 -0
- package/dist/utils/manifest.d.ts +11 -0
- package/dist/utils/manifest.js +115 -0
- package/dist/utils/manifest.mjs +47 -0
- package/dist/utils/ssr.d.ts +50 -0
- package/dist/utils/ssr.js +260 -0
- package/dist/utils/ssr.mjs +175 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +96 -0
- package/dist/utils.mjs +4 -0
- package/package.json +83 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function mergeStats(browserStats, nodeStats) {
|
|
9
|
+
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
10
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
11
|
+
if ('publicPath' in browserStats.metaData) {
|
|
12
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
13
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
14
|
+
}
|
|
15
|
+
return browserStats;
|
|
16
|
+
}
|
|
17
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
18
|
+
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
19
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
20
|
+
if ('publicPath' in browserManifest.metaData) {
|
|
21
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
22
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
23
|
+
}
|
|
24
|
+
return browserManifest;
|
|
25
|
+
}
|
|
26
|
+
function mergeStatsAndManifest(nodeAssets, browserAssets) {
|
|
27
|
+
const { stats: browserStats, manifest: browserManifest } = browserAssets;
|
|
28
|
+
const { stats: nodeStats, manifest: nodeManifest } = nodeAssets;
|
|
29
|
+
if (!browserStats || !nodeStats || !browserManifest || !nodeManifest) {
|
|
30
|
+
throw new Error('Failed to read stats or manifest assets for merge');
|
|
31
|
+
}
|
|
32
|
+
const mergedStats = mergeStats(browserStats.data, nodeStats.data);
|
|
33
|
+
const mergedManifest = mergeManifest(browserManifest.data, nodeManifest.data);
|
|
34
|
+
return {
|
|
35
|
+
mergedStats: mergedStats,
|
|
36
|
+
mergedStatsFilePath: browserStats.filename,
|
|
37
|
+
mergedManifest: mergedManifest,
|
|
38
|
+
mergedManifestFilePath: browserManifest.filename
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function updateStatsAndManifest(nodeAssets, browserAssets, outputDir) {
|
|
42
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodeAssets, browserAssets);
|
|
43
|
+
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
44
|
+
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { updateStatsAndManifest };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { EnvironmentConfig, RsbuildConfig, Rspack, EnvironmentContext } from '@rsbuild/core';
|
|
2
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
export declare const SSR_DIR = "ssr";
|
|
4
|
+
export declare const SSR_ENV_NAME = "mf-ssr";
|
|
5
|
+
export declare const ENV_NAME = "mf";
|
|
6
|
+
export declare function setSSREnv(): void;
|
|
7
|
+
export declare function patchNodeConfig(config: Rspack.Configuration, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
8
|
+
export declare function patchSSRRspackConfig(config: Rspack.Configuration, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, ssrDir: string, callerName?: string, resetEntry?: boolean, modifyPublicPath?: boolean): Rspack.RspackOptions;
|
|
9
|
+
export declare function patchToolsTspack(envConfig: EnvironmentConfig, fn: (config: Rspack.RspackOptions, { environment }: {
|
|
10
|
+
environment: EnvironmentContext;
|
|
11
|
+
}) => void): void;
|
|
12
|
+
export declare function createSSRREnvConfig(envConfig: EnvironmentConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, ssrDir: string, rsbuildConfig: RsbuildConfig, callerName?: string): EnvironmentConfig;
|
|
13
|
+
export declare function patchNodeMFConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
14
|
+
export declare function createSSRMFConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): {
|
|
15
|
+
exposes?: moduleFederationPlugin.Exposes;
|
|
16
|
+
filename?: string;
|
|
17
|
+
library?: moduleFederationPlugin.LibraryOptions;
|
|
18
|
+
name?: string;
|
|
19
|
+
remoteType?: moduleFederationPlugin.ExternalsType;
|
|
20
|
+
remotes?: moduleFederationPlugin.Remotes;
|
|
21
|
+
runtime?: moduleFederationPlugin.EntryRuntime;
|
|
22
|
+
shareScope?: string | string[];
|
|
23
|
+
shareStrategy?: moduleFederationPlugin.SharedStrategy;
|
|
24
|
+
shared?: moduleFederationPlugin.Shared;
|
|
25
|
+
runtimePlugins?: (string | [string, Record<string, unknown>])[];
|
|
26
|
+
getPublicPath?: string;
|
|
27
|
+
implementation?: string;
|
|
28
|
+
manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
|
|
29
|
+
dev?: boolean | moduleFederationPlugin.PluginDevOptions;
|
|
30
|
+
dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
|
|
31
|
+
virtualRuntimeEntry?: boolean;
|
|
32
|
+
experiments?: {
|
|
33
|
+
externalRuntime?: boolean;
|
|
34
|
+
provideExternalRuntime?: boolean;
|
|
35
|
+
asyncStartup?: boolean;
|
|
36
|
+
optimization?: {
|
|
37
|
+
disableSnapshot?: boolean;
|
|
38
|
+
target?: "web" | "node";
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
bridge?: {
|
|
42
|
+
enableBridgeRouter?: boolean;
|
|
43
|
+
disableAlias?: boolean;
|
|
44
|
+
};
|
|
45
|
+
async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
|
|
46
|
+
treeShakingDir?: string;
|
|
47
|
+
injectTreeShakingUsedExports?: boolean;
|
|
48
|
+
treeShakingSharedExcludePlugins?: string[];
|
|
49
|
+
treeShakingSharedPlugins?: string[];
|
|
50
|
+
};
|
|
@@ -0,0 +1,260 @@
|
|
|
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
|
+
function patchNodeMFConfig(mfConfig) {
|
|
216
|
+
if (mfConfig.remotes) {
|
|
217
|
+
mfConfig.remoteType = 'script';
|
|
218
|
+
}
|
|
219
|
+
mfConfig.exposes = {
|
|
220
|
+
...mfConfig.exposes
|
|
221
|
+
};
|
|
222
|
+
mfConfig.library = {
|
|
223
|
+
...mfConfig.library,
|
|
224
|
+
name: mfConfig.name,
|
|
225
|
+
type: mfConfig.library?.type ?? 'commonjs-module'
|
|
226
|
+
};
|
|
227
|
+
mfConfig.runtimePlugins = [
|
|
228
|
+
...mfConfig.runtimePlugins || []
|
|
229
|
+
];
|
|
230
|
+
mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/runtimePlugin'));
|
|
231
|
+
if (isDev()) {
|
|
232
|
+
mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function createSSRMFConfig(mfConfig) {
|
|
236
|
+
const ssrMFConfig = {
|
|
237
|
+
...mfConfig
|
|
238
|
+
};
|
|
239
|
+
patchNodeMFConfig(ssrMFConfig);
|
|
240
|
+
ssrMFConfig.dts = false;
|
|
241
|
+
ssrMFConfig.dev = false;
|
|
242
|
+
return ssrMFConfig;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
exports.ENV_NAME = __webpack_exports__.ENV_NAME;
|
|
246
|
+
exports.SSR_DIR = __webpack_exports__.SSR_DIR;
|
|
247
|
+
exports.SSR_ENV_NAME = __webpack_exports__.SSR_ENV_NAME;
|
|
248
|
+
exports.createSSRMFConfig = __webpack_exports__.createSSRMFConfig;
|
|
249
|
+
exports.createSSRREnvConfig = __webpack_exports__.createSSRREnvConfig;
|
|
250
|
+
exports.patchNodeConfig = __webpack_exports__.patchNodeConfig;
|
|
251
|
+
exports.patchNodeMFConfig = __webpack_exports__.patchNodeMFConfig;
|
|
252
|
+
exports.patchSSRRspackConfig = __webpack_exports__.patchSSRRspackConfig;
|
|
253
|
+
exports.patchToolsTspack = __webpack_exports__.patchToolsTspack;
|
|
254
|
+
exports.setSSREnv = __webpack_exports__.setSSREnv;
|
|
255
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
256
|
+
if(["ENV_NAME","SSR_DIR","SSR_ENV_NAME","createSSRMFConfig","createSSRREnvConfig","patchNodeConfig","patchNodeMFConfig","patchSSRRspackConfig","patchToolsTspack","setSSREnv"].indexOf(__rspack_i) === -1) {
|
|
257
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
function patchNodeMFConfig(mfConfig) {
|
|
146
|
+
if (mfConfig.remotes) {
|
|
147
|
+
mfConfig.remoteType = 'script';
|
|
148
|
+
}
|
|
149
|
+
mfConfig.exposes = {
|
|
150
|
+
...mfConfig.exposes
|
|
151
|
+
};
|
|
152
|
+
mfConfig.library = {
|
|
153
|
+
...mfConfig.library,
|
|
154
|
+
name: mfConfig.name,
|
|
155
|
+
type: mfConfig.library?.type ?? 'commonjs-module'
|
|
156
|
+
};
|
|
157
|
+
mfConfig.runtimePlugins = [
|
|
158
|
+
...mfConfig.runtimePlugins || []
|
|
159
|
+
];
|
|
160
|
+
mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/runtimePlugin'));
|
|
161
|
+
if (isDev()) {
|
|
162
|
+
mfConfig.runtimePlugins.push(resolveOrRequest('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function createSSRMFConfig(mfConfig) {
|
|
166
|
+
const ssrMFConfig = {
|
|
167
|
+
...mfConfig
|
|
168
|
+
};
|
|
169
|
+
patchNodeMFConfig(ssrMFConfig);
|
|
170
|
+
ssrMFConfig.dts = false;
|
|
171
|
+
ssrMFConfig.dev = false;
|
|
172
|
+
return ssrMFConfig;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { ENV_NAME, SSR_DIR, SSR_ENV_NAME, createSSRMFConfig, createSSRREnvConfig, patchNodeConfig, patchNodeMFConfig, patchSSRRspackConfig, patchToolsTspack, setSSREnv };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils/index';
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
var __webpack_modules__ = ({
|
|
10
|
+
"./utils/index"(module) {
|
|
11
|
+
module.exports = require("./utils/index.js");
|
|
12
|
+
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
});
|
|
16
|
+
// The module cache
|
|
17
|
+
var __webpack_module_cache__ = {};
|
|
18
|
+
|
|
19
|
+
// The require function
|
|
20
|
+
function __webpack_require__(moduleId) {
|
|
21
|
+
|
|
22
|
+
// Check if module is in cache
|
|
23
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
24
|
+
if (cachedModule !== undefined) {
|
|
25
|
+
return cachedModule.exports;
|
|
26
|
+
}
|
|
27
|
+
// Create a new module (and put it into the cache)
|
|
28
|
+
var module = (__webpack_module_cache__[moduleId] = {
|
|
29
|
+
exports: {}
|
|
30
|
+
});
|
|
31
|
+
// Execute the module function
|
|
32
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
33
|
+
|
|
34
|
+
// Return the exports of the module
|
|
35
|
+
return module.exports;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// webpack/runtime/compat_get_default_export
|
|
40
|
+
(() => {
|
|
41
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
42
|
+
__webpack_require__.n = (module) => {
|
|
43
|
+
var getter = module && module.__esModule ?
|
|
44
|
+
() => (module['default']) :
|
|
45
|
+
() => (module);
|
|
46
|
+
__webpack_require__.d(getter, { a: getter });
|
|
47
|
+
return getter;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
})();
|
|
51
|
+
// webpack/runtime/define_property_getters
|
|
52
|
+
(() => {
|
|
53
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
54
|
+
var define = (defs, kind) => {
|
|
55
|
+
for(var key in defs) {
|
|
56
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
57
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
define(getters, "get");
|
|
62
|
+
define(values, "value");
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
// webpack/runtime/has_own_property
|
|
66
|
+
(() => {
|
|
67
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
68
|
+
})();
|
|
69
|
+
// webpack/runtime/make_namespace_object
|
|
70
|
+
(() => {
|
|
71
|
+
// define __esModule on exports
|
|
72
|
+
__webpack_require__.r = (exports) => {
|
|
73
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
74
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
75
|
+
}
|
|
76
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
77
|
+
};
|
|
78
|
+
})();
|
|
79
|
+
var __webpack_exports__ = {};
|
|
80
|
+
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
81
|
+
(() => {
|
|
82
|
+
__webpack_require__.r(__webpack_exports__);
|
|
83
|
+
/* import */ var _utils_index__rspack_import_0 = __webpack_require__("./utils/index");
|
|
84
|
+
/* import */ var _utils_index__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_utils_index__rspack_import_0);
|
|
85
|
+
|
|
86
|
+
/* reexport */ var __rspack_reexport = {};
|
|
87
|
+
/* reexport */ for( const __rspack_import_key in _utils_index__rspack_import_0) if(__rspack_import_key !== "default") __rspack_reexport[__rspack_import_key] =() => _utils_index__rspack_import_0[__rspack_import_key]
|
|
88
|
+
/* reexport */ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
})();
|
|
92
|
+
|
|
93
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
94
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
95
|
+
}
|
|
96
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/utils.mjs
ADDED