@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,389 @@
|
|
|
1
|
+
import { parseOptions } from "@module-federation/enhanced";
|
|
2
|
+
import { ModuleFederationPlugin, PLUGIN_NAME, TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
3
|
+
import { createModuleFederationConfig, getManifestFileName, isRequiredVersion } from "@module-federation/sdk";
|
|
4
|
+
import logger from "../logger.mjs";
|
|
5
|
+
import { SSR_DIR, SSR_ENV_NAME, addDataFetchExposes, autoDeleteSplitChunkCacheGroups, createSSRMFConfig, createSSRREnvConfig, isRegExp, patchSSRRspackConfig, setSSREnv, updateStatsAndManifest } from "../utils.mjs";
|
|
6
|
+
import { CALL_NAME_MAP, RSPRESS_BUNDLER_CONFIG_NAME, RSPRESS_SSG_MD_ENV_NAME, RSPRESS_SSR_DIR } from "../constant.mjs";
|
|
7
|
+
import { patchNodeConfig, patchToolsTspack } from "../utils/ssr.mjs";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
24
|
+
const RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
|
|
25
|
+
|
|
26
|
+
const LIB_FORMAT = [
|
|
27
|
+
'umd',
|
|
28
|
+
'modern-module'
|
|
29
|
+
];
|
|
30
|
+
const DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
|
|
31
|
+
const DEFAULT_WEB_ENVIRONMENT_NAME = 'web';
|
|
32
|
+
const DEFAULT_NODE_ENVIRONMENT_NAME = 'node';
|
|
33
|
+
const resolveDefaultEnvironmentName = ({ callerName, target })=>{
|
|
34
|
+
if (callerName === CALL_NAME_MAP.RSLIB) {
|
|
35
|
+
return DEFAULT_MF_ENVIRONMENT_NAME;
|
|
36
|
+
}
|
|
37
|
+
if (callerName === CALL_NAME_MAP.RSPRESS) {
|
|
38
|
+
if (target === 'node') {
|
|
39
|
+
return DEFAULT_NODE_ENVIRONMENT_NAME;
|
|
40
|
+
}
|
|
41
|
+
return DEFAULT_WEB_ENVIRONMENT_NAME;
|
|
42
|
+
}
|
|
43
|
+
if (target === 'node') {
|
|
44
|
+
return DEFAULT_NODE_ENVIRONMENT_NAME;
|
|
45
|
+
}
|
|
46
|
+
return DEFAULT_WEB_ENVIRONMENT_NAME;
|
|
47
|
+
};
|
|
48
|
+
function isStoryBook(rsbuildConfig) {
|
|
49
|
+
if (rsbuildConfig.plugins?.find((p)=>p && 'name' in p && p.name === 'module-federation-storybook-plugin')) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function isMFFormat(bundlerConfig) {
|
|
55
|
+
const library = bundlerConfig.output?.library;
|
|
56
|
+
if (bundlerConfig.name === SSR_ENV_NAME) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return !(typeof library === 'object' && !Array.isArray(library) && 'type' in library && // if the type is umd/modern-module or commonjs*, means this is a normal library , not mf
|
|
60
|
+
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
61
|
+
}
|
|
62
|
+
const isSSRConfig = (bundlerConfigName)=>Boolean(bundlerConfigName === SSR_ENV_NAME);
|
|
63
|
+
const isRspressSSGConfig = (bundlerConfigName)=>{
|
|
64
|
+
return [
|
|
65
|
+
RSPRESS_BUNDLER_CONFIG_NAME,
|
|
66
|
+
RSPRESS_SSG_MD_ENV_NAME
|
|
67
|
+
].includes(bundlerConfigName || '');
|
|
68
|
+
};
|
|
69
|
+
const pluginModuleFederation = (moduleFederationOptions, rsbuildOptions)=>({
|
|
70
|
+
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
71
|
+
setup: (api)=>{
|
|
72
|
+
if (!moduleFederationOptions?.name) {
|
|
73
|
+
throw new Error('The module federation option "name" is required in @module-federation/rsbuild-plugin.');
|
|
74
|
+
}
|
|
75
|
+
const { target = 'web', ssr = undefined, ssrDir = SSR_DIR, environment: configuredEnvironment } = rsbuildOptions || {};
|
|
76
|
+
if (ssr) {
|
|
77
|
+
throw new Error("The `ssr` option is deprecated. If you want to enable SSR, please use `target: 'dual'` instead.");
|
|
78
|
+
}
|
|
79
|
+
const { callerName } = api.context;
|
|
80
|
+
const originalRsbuildConfig = api.getRsbuildConfig();
|
|
81
|
+
if (!callerName) {
|
|
82
|
+
throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
83
|
+
}
|
|
84
|
+
const isRslib = callerName === CALL_NAME_MAP.RSLIB;
|
|
85
|
+
const isRspress = callerName === CALL_NAME_MAP.RSPRESS;
|
|
86
|
+
const isSSR = target === 'dual';
|
|
87
|
+
const environment = configuredEnvironment ?? resolveDefaultEnvironmentName({
|
|
88
|
+
callerName,
|
|
89
|
+
target
|
|
90
|
+
});
|
|
91
|
+
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
92
|
+
if (!isRslib && !isRspress) {
|
|
93
|
+
throw new Error(`'target' option is only supported in Rslib.`);
|
|
94
|
+
}
|
|
95
|
+
const rsbuildConfig = api.getRsbuildConfig();
|
|
96
|
+
if (!isRspress && (!rsbuildConfig.environments?.[environment] || Object.keys(rsbuildConfig.environments).some((key)=>key.startsWith(environment) && key !== environment))) {
|
|
97
|
+
throw new Error(`Please set ${RSBUILD_PLUGIN_NAME} as global plugin in rslib.config.ts if you set 'target: "dual"'.`);
|
|
98
|
+
}
|
|
99
|
+
setSSREnv();
|
|
100
|
+
}
|
|
101
|
+
const sharedOptions = parseOptions(moduleFederationOptions.shared || [], (item, key)=>{
|
|
102
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
103
|
+
const config = item === key || !isRequiredVersion(item) ? {
|
|
104
|
+
import: item
|
|
105
|
+
} : {
|
|
106
|
+
import: key,
|
|
107
|
+
requiredVersion: item
|
|
108
|
+
};
|
|
109
|
+
return config;
|
|
110
|
+
}, (item)=>item);
|
|
111
|
+
// shared[0] is the shared name
|
|
112
|
+
const shared = sharedOptions.map((shared)=>shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0]);
|
|
113
|
+
api.modifyRsbuildConfig((config)=>{
|
|
114
|
+
// skip storybook
|
|
115
|
+
if (isStoryBook(config)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Change some default configs for remote modules
|
|
119
|
+
if (moduleFederationOptions.exposes) {
|
|
120
|
+
config.dev ||= {};
|
|
121
|
+
config.server ||= {};
|
|
122
|
+
const userConfig = api.getRsbuildConfig('original');
|
|
123
|
+
// Allow remote modules to be loaded by setting CORS headers
|
|
124
|
+
// This is required for MF to work properly across different origins
|
|
125
|
+
config.server.headers ||= {};
|
|
126
|
+
if (!config.server.headers['Access-Control-Allow-Origin'] && !(typeof userConfig.server?.cors === 'object' && userConfig.server.cors.origin)) {
|
|
127
|
+
const corsWarnMsgs = [
|
|
128
|
+
'Detect that CORS options are not set, mf Rsbuild plugin will add default cors header: server.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins in "server.cors" instead.',
|
|
129
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
130
|
+
];
|
|
131
|
+
!isRslib && !isRspress && logger.warn(corsWarnMsgs.join('\n'));
|
|
132
|
+
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
133
|
+
}
|
|
134
|
+
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
135
|
+
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
136
|
+
if (config.server?.port && !config.dev.client?.port) {
|
|
137
|
+
config.dev.client ||= {};
|
|
138
|
+
config.dev.client.port = config.server.port;
|
|
139
|
+
}
|
|
140
|
+
// Change the default assetPrefix to `true` for remote modules.
|
|
141
|
+
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
142
|
+
const originalConfig = api.getRsbuildConfig('original');
|
|
143
|
+
if (originalConfig.dev?.assetPrefix === undefined && config.dev.assetPrefix === config.server?.base) {
|
|
144
|
+
config.dev.assetPrefix = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (isSSR) {
|
|
148
|
+
if (config.environments?.[SSR_ENV_NAME]) {
|
|
149
|
+
throw new Error(`'${SSR_ENV_NAME}' environment is already defined.Please use another name.`);
|
|
150
|
+
}
|
|
151
|
+
const currentEnvironment = config.environments?.[environment];
|
|
152
|
+
if (!currentEnvironment) {
|
|
153
|
+
throw new Error(`Can not find environment '${environment}' when enabling SSR.`);
|
|
154
|
+
}
|
|
155
|
+
config.environments[SSR_ENV_NAME] = createSSRREnvConfig(currentEnvironment, moduleFederationOptions, ssrDir, config, callerName);
|
|
156
|
+
const ssgMDEnv = config.environments[RSPRESS_SSG_MD_ENV_NAME];
|
|
157
|
+
if (isRspress && ssgMDEnv) {
|
|
158
|
+
patchToolsTspack(ssgMDEnv, (config, { environment })=>{
|
|
159
|
+
config.target = 'async-node';
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
} else if (target === 'node') {
|
|
163
|
+
const nodeTargetEnv = config.environments?.[environment];
|
|
164
|
+
if (!nodeTargetEnv) {
|
|
165
|
+
const availableEnvironments = Object.keys(config.environments || {});
|
|
166
|
+
const availableEnvironmentsLabel = availableEnvironments.length > 0 ? availableEnvironments.join(', ') : '(none)';
|
|
167
|
+
throw new Error(`Can not find environment '${environment}' when using target: 'node'. Available environments: ${availableEnvironmentsLabel}.`);
|
|
168
|
+
}
|
|
169
|
+
patchToolsTspack(nodeTargetEnv, (config, { environment })=>{
|
|
170
|
+
config.target = 'async-node';
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
api.modifyEnvironmentConfig((config)=>{
|
|
175
|
+
// Module Federation runtime uses ES6+ syntax,
|
|
176
|
+
// adding to include and let SWC transform it
|
|
177
|
+
config.source.include = [
|
|
178
|
+
...config.source.include || [],
|
|
179
|
+
/@module-federation[\\/]/
|
|
180
|
+
];
|
|
181
|
+
return config;
|
|
182
|
+
});
|
|
183
|
+
const generateMergedStatsAndManifestOptions = {
|
|
184
|
+
options: {
|
|
185
|
+
nodePlugin: undefined,
|
|
186
|
+
browserPlugin: undefined,
|
|
187
|
+
rspressSSGPlugin: undefined,
|
|
188
|
+
distOutputDir: undefined,
|
|
189
|
+
browserEnvironmentName: undefined,
|
|
190
|
+
nodeEnvironmentName: undefined
|
|
191
|
+
},
|
|
192
|
+
assetResources: {},
|
|
193
|
+
isSSRConfig: isSSRConfig,
|
|
194
|
+
isRspressSSGConfig: isRspressSSGConfig
|
|
195
|
+
};
|
|
196
|
+
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
197
|
+
const defaultBrowserEnvironmentName = environment;
|
|
198
|
+
const assetFileNames = getManifestFileName(moduleFederationOptions.manifest);
|
|
199
|
+
if (moduleFederationOptions.manifest !== false) {
|
|
200
|
+
api.processAssets({
|
|
201
|
+
stage: 'report'
|
|
202
|
+
}, ({ assets, environment: envContext })=>{
|
|
203
|
+
const expectedBrowserEnv = generateMergedStatsAndManifestOptions.options.browserEnvironmentName ?? defaultBrowserEnvironmentName;
|
|
204
|
+
const expectedNodeEnv = generateMergedStatsAndManifestOptions.options.nodeEnvironmentName ?? SSR_ENV_NAME;
|
|
205
|
+
const envName = envContext.name;
|
|
206
|
+
if (envName !== expectedBrowserEnv && envName !== expectedNodeEnv) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
210
|
+
const targetResources = assetResources[envName] || (assetResources[envName] = {});
|
|
211
|
+
const statsAsset = assets[assetFileNames.statsFileName];
|
|
212
|
+
if (statsAsset) {
|
|
213
|
+
try {
|
|
214
|
+
const raw = statsAsset.source();
|
|
215
|
+
const content = typeof raw === 'string' ? raw : raw.toString();
|
|
216
|
+
targetResources.stats = {
|
|
217
|
+
data: JSON.parse(content),
|
|
218
|
+
filename: assetFileNames.statsFileName
|
|
219
|
+
};
|
|
220
|
+
} catch (err) {
|
|
221
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
222
|
+
logger.error(`Failed to parse stats asset "${assetFileNames.statsFileName}" for environment "${envName}": ${message} `);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const manifestAsset = assets[assetFileNames.manifestFileName];
|
|
226
|
+
if (manifestAsset) {
|
|
227
|
+
try {
|
|
228
|
+
const raw = manifestAsset.source();
|
|
229
|
+
const content = typeof raw === 'string' ? raw : raw.toString();
|
|
230
|
+
targetResources.manifest = {
|
|
231
|
+
data: JSON.parse(content),
|
|
232
|
+
filename: assetFileNames.manifestFileName
|
|
233
|
+
};
|
|
234
|
+
} catch (err) {
|
|
235
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
236
|
+
logger.error(`Failed to parse manifest asset "${assetFileNames.manifestFileName}" for environment "${envName}": ${message} `);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
|
|
242
|
+
if (!bundlerConfigs) {
|
|
243
|
+
throw new Error('Can not get bundlerConfigs!');
|
|
244
|
+
}
|
|
245
|
+
bundlerConfigs.forEach((bundlerConfig)=>{
|
|
246
|
+
const bundlerConfigName = bundlerConfig.name || '';
|
|
247
|
+
const isConfiguredEnvironmentConfig = bundlerConfigName === environment;
|
|
248
|
+
const isNodeTargetEnvironmentConfig = target === 'node' && bundlerConfigName === environment;
|
|
249
|
+
const isRspressSSGEnvironmentConfig = isRspressSSGConfig(bundlerConfig.name);
|
|
250
|
+
const isActiveRspressSSGEnvironmentConfig = isRspress && isRspressSSGEnvironmentConfig;
|
|
251
|
+
const shouldUseSSRPluginConfig = isSSRConfig(bundlerConfig.name) || isNodeTargetEnvironmentConfig;
|
|
252
|
+
if (target === 'node' && !isNodeTargetEnvironmentConfig && !isActiveRspressSSGEnvironmentConfig) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
// For non-node targets, scope each plugin instance to its configured
|
|
256
|
+
// environment plus explicit SSR/SSG environments. This prevents a
|
|
257
|
+
// browser-targeted instance from mutating SSR configs.
|
|
258
|
+
if (target !== 'node' && !isConfiguredEnvironmentConfig && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (!isMFFormat(bundlerConfig) && !isRspress && !isNodeTargetEnvironmentConfig) {
|
|
262
|
+
return;
|
|
263
|
+
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
264
|
+
bundlerConfig.output.uniqueName = `${moduleFederationOptions.name} -storybook - host`;
|
|
265
|
+
} else {
|
|
266
|
+
// mf
|
|
267
|
+
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig?.optimization?.splitChunks);
|
|
268
|
+
addDataFetchExposes(moduleFederationOptions.exposes, shouldUseSSRPluginConfig);
|
|
269
|
+
const ssrModuleFederationOptions = shouldUseSSRPluginConfig ? createSSRMFConfig(moduleFederationOptions) : undefined;
|
|
270
|
+
delete bundlerConfig.optimization?.runtimeChunk;
|
|
271
|
+
const externals = bundlerConfig.externals;
|
|
272
|
+
if (Array.isArray(externals)) {
|
|
273
|
+
const sharedModules = new Set();
|
|
274
|
+
bundlerConfig.externals = externals.filter((ext)=>{
|
|
275
|
+
let sharedModule;
|
|
276
|
+
if (isRegExp(ext)) {
|
|
277
|
+
const match = shared.some((dep)=>{
|
|
278
|
+
if (ext.test(dep) || ext.test("@module-federation/rsbuild-plugin")) {
|
|
279
|
+
sharedModule = dep;
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
});
|
|
284
|
+
match && sharedModule && sharedModules.add(sharedModule);
|
|
285
|
+
return !match;
|
|
286
|
+
}
|
|
287
|
+
if (typeof ext === 'string') {
|
|
288
|
+
if (ext === "@module-federation/rsbuild-plugin") {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
const match = shared.some((dep)=>{
|
|
292
|
+
if (dep === ext) {
|
|
293
|
+
sharedModule = dep;
|
|
294
|
+
}
|
|
295
|
+
return dep === ext;
|
|
296
|
+
});
|
|
297
|
+
if (match) {
|
|
298
|
+
sharedModule && sharedModules.add(sharedModule);
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
});
|
|
305
|
+
if (sharedModules.size > 0) {
|
|
306
|
+
for (const sharedModule of sharedModules){
|
|
307
|
+
logger.log(`${sharedModule} is removed from externals because it is a shared module.`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!bundlerConfig.output?.chunkLoadingGlobal && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig && target !== 'node') {
|
|
312
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${moduleFederationOptions.name}`;
|
|
313
|
+
}
|
|
314
|
+
if (isNodeTargetEnvironmentConfig) {
|
|
315
|
+
patchNodeConfig(bundlerConfig, ssrModuleFederationOptions ?? moduleFederationOptions);
|
|
316
|
+
}
|
|
317
|
+
// `uniqueName` is required for react refresh to work
|
|
318
|
+
if (!bundlerConfig.output?.uniqueName) {
|
|
319
|
+
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
320
|
+
}
|
|
321
|
+
// Set default publicPath to 'auto' if not explicitly configured
|
|
322
|
+
// This allows remote chunks to load from the same origin as the remote application's manifest
|
|
323
|
+
if (bundlerConfig.output?.publicPath === undefined && !shouldUseSSRPluginConfig && !isActiveRspressSSGEnvironmentConfig) {
|
|
324
|
+
bundlerConfig.output.publicPath = 'auto';
|
|
325
|
+
}
|
|
326
|
+
if (!bundlerConfig.plugins.find((p)=>p && p.name === PLUGIN_NAME)) {
|
|
327
|
+
if (shouldUseSSRPluginConfig) {
|
|
328
|
+
const ssrMFConfig = ssrModuleFederationOptions ?? createSSRMFConfig(moduleFederationOptions);
|
|
329
|
+
generateMergedStatsAndManifestOptions.options.nodePlugin = new ModuleFederationPlugin(ssrMFConfig);
|
|
330
|
+
generateMergedStatsAndManifestOptions.options.nodeEnvironmentName = bundlerConfig.name || SSR_ENV_NAME;
|
|
331
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
332
|
+
return;
|
|
333
|
+
} else if (isActiveRspressSSGEnvironmentConfig) {
|
|
334
|
+
const mfConfig = {
|
|
335
|
+
...createSSRMFConfig(moduleFederationOptions),
|
|
336
|
+
// expose in mf-ssg env
|
|
337
|
+
exposes: {},
|
|
338
|
+
manifest: false,
|
|
339
|
+
library: undefined
|
|
340
|
+
};
|
|
341
|
+
patchSSRRspackConfig(bundlerConfig, mfConfig, RSPRESS_SSR_DIR, callerName, false, false);
|
|
342
|
+
bundlerConfig.output ||= {};
|
|
343
|
+
bundlerConfig.output.publicPath = '/';
|
|
344
|
+
// MF depend on asyncChunks
|
|
345
|
+
bundlerConfig.output.asyncChunks = undefined;
|
|
346
|
+
const p = new ModuleFederationPlugin(mfConfig);
|
|
347
|
+
if (bundlerConfig.name === RSPRESS_BUNDLER_CONFIG_NAME) {
|
|
348
|
+
generateMergedStatsAndManifestOptions.options.rspressSSGPlugin = p;
|
|
349
|
+
}
|
|
350
|
+
bundlerConfig.plugins.push(p);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
generateMergedStatsAndManifestOptions.options.browserPlugin = new ModuleFederationPlugin(moduleFederationOptions);
|
|
354
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = bundlerConfig.output?.path || '';
|
|
355
|
+
generateMergedStatsAndManifestOptions.options.browserEnvironmentName = bundlerConfig.name || defaultBrowserEnvironmentName;
|
|
356
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
const generateMergedStatsAndManifest = ()=>{
|
|
362
|
+
const { distOutputDir, browserEnvironmentName, nodeEnvironmentName } = generateMergedStatsAndManifestOptions.options;
|
|
363
|
+
if (!distOutputDir || !browserEnvironmentName || !nodeEnvironmentName) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const assetResources = generateMergedStatsAndManifestOptions.assetResources;
|
|
367
|
+
const browserAssets = assetResources[browserEnvironmentName];
|
|
368
|
+
const nodeAssets = assetResources[nodeEnvironmentName];
|
|
369
|
+
if (!browserAssets || !nodeAssets) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
|
|
374
|
+
} catch (err) {
|
|
375
|
+
logger.error(err);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
api.onDevCompileDone(()=>{
|
|
379
|
+
generateMergedStatsAndManifest();
|
|
380
|
+
});
|
|
381
|
+
api.onAfterBuild(()=>{
|
|
382
|
+
generateMergedStatsAndManifest();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
export { PLUGIN_NAME, RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, SSR_DIR, TreeShakingSharedPlugin, createModuleFederationConfig, isMFFormat, pluginModuleFederation };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DEFAULT_ASSET_PREFIX = "/";
|
|
2
|
+
export declare const DATA_FETCH_IDENTIFIER = "data";
|
|
3
|
+
export declare const DATA_FETCH_CLIENT_SUFFIX = ".client";
|
|
4
|
+
export declare const CALL_NAME_MAP: {
|
|
5
|
+
RSPRESS: string;
|
|
6
|
+
RSLIB: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const RSPRESS_BUNDLER_CONFIG_NAME = "node";
|
|
9
|
+
export declare const RSPRESS_SSG_MD_ENV_NAME = "node_md";
|
|
10
|
+
export declare const RSPRESS_SSR_DIR = "ssr";
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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/define_property_getters
|
|
13
|
+
(() => {
|
|
14
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
15
|
+
var define = (defs, kind) => {
|
|
16
|
+
for(var key in defs) {
|
|
17
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
define(getters, "get");
|
|
23
|
+
define(values, "value");
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
// webpack/runtime/has_own_property
|
|
27
|
+
(() => {
|
|
28
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
29
|
+
})();
|
|
30
|
+
// webpack/runtime/make_namespace_object
|
|
31
|
+
(() => {
|
|
32
|
+
// define __esModule on exports
|
|
33
|
+
__webpack_require__.r = (exports) => {
|
|
34
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
35
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __webpack_exports__ = {};
|
|
41
|
+
__webpack_require__.r(__webpack_exports__);
|
|
42
|
+
const DEFAULT_ASSET_PREFIX = '/';
|
|
43
|
+
const DATA_FETCH_IDENTIFIER = 'data';
|
|
44
|
+
const DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
45
|
+
const CALL_NAME_MAP = {
|
|
46
|
+
RSPRESS: 'rspress',
|
|
47
|
+
RSLIB: 'rslib'
|
|
48
|
+
};
|
|
49
|
+
const RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
50
|
+
const RSPRESS_SSG_MD_ENV_NAME = 'node_md';
|
|
51
|
+
const RSPRESS_SSR_DIR = 'ssr';
|
|
52
|
+
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
}, {
|
|
55
|
+
CALL_NAME_MAP: CALL_NAME_MAP,
|
|
56
|
+
DATA_FETCH_CLIENT_SUFFIX: DATA_FETCH_CLIENT_SUFFIX,
|
|
57
|
+
DATA_FETCH_IDENTIFIER: DATA_FETCH_IDENTIFIER,
|
|
58
|
+
DEFAULT_ASSET_PREFIX: DEFAULT_ASSET_PREFIX,
|
|
59
|
+
RSPRESS_BUNDLER_CONFIG_NAME: RSPRESS_BUNDLER_CONFIG_NAME,
|
|
60
|
+
RSPRESS_SSG_MD_ENV_NAME: RSPRESS_SSG_MD_ENV_NAME,
|
|
61
|
+
RSPRESS_SSR_DIR: RSPRESS_SSR_DIR
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
exports.CALL_NAME_MAP = __webpack_exports__.CALL_NAME_MAP;
|
|
65
|
+
exports.DATA_FETCH_CLIENT_SUFFIX = __webpack_exports__.DATA_FETCH_CLIENT_SUFFIX;
|
|
66
|
+
exports.DATA_FETCH_IDENTIFIER = __webpack_exports__.DATA_FETCH_IDENTIFIER;
|
|
67
|
+
exports.DEFAULT_ASSET_PREFIX = __webpack_exports__.DEFAULT_ASSET_PREFIX;
|
|
68
|
+
exports.RSPRESS_BUNDLER_CONFIG_NAME = __webpack_exports__.RSPRESS_BUNDLER_CONFIG_NAME;
|
|
69
|
+
exports.RSPRESS_SSG_MD_ENV_NAME = __webpack_exports__.RSPRESS_SSG_MD_ENV_NAME;
|
|
70
|
+
exports.RSPRESS_SSR_DIR = __webpack_exports__.RSPRESS_SSR_DIR;
|
|
71
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
72
|
+
if(["CALL_NAME_MAP","DATA_FETCH_CLIENT_SUFFIX","DATA_FETCH_IDENTIFIER","DEFAULT_ASSET_PREFIX","RSPRESS_BUNDLER_CONFIG_NAME","RSPRESS_SSG_MD_ENV_NAME","RSPRESS_SSR_DIR"].indexOf(__rspack_i) === -1) {
|
|
73
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const DEFAULT_ASSET_PREFIX = '/';
|
|
2
|
+
const DATA_FETCH_IDENTIFIER = 'data';
|
|
3
|
+
const DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
4
|
+
const CALL_NAME_MAP = {
|
|
5
|
+
RSPRESS: 'rspress',
|
|
6
|
+
RSLIB: 'rslib'
|
|
7
|
+
};
|
|
8
|
+
const RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
9
|
+
const RSPRESS_SSG_MD_ENV_NAME = 'node_md';
|
|
10
|
+
const RSPRESS_SSR_DIR = 'ssr';
|
|
11
|
+
|
|
12
|
+
export { CALL_NAME_MAP, DATA_FETCH_CLIENT_SUFFIX, DATA_FETCH_IDENTIFIER, DEFAULT_ASSET_PREFIX, RSPRESS_BUNDLER_CONFIG_NAME, RSPRESS_SSG_MD_ENV_NAME, RSPRESS_SSR_DIR };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli/index';
|
package/dist/index.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
|
+
"./cli/index"(module) {
|
|
11
|
+
module.exports = require("./cli/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 _cli_index__rspack_import_0 = __webpack_require__("./cli/index");
|
|
84
|
+
/* import */ var _cli_index__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_cli_index__rspack_import_0);
|
|
85
|
+
|
|
86
|
+
/* reexport */ var __rspack_reexport = {};
|
|
87
|
+
/* reexport */ for( const __rspack_import_key in _cli_index__rspack_import_0) if(__rspack_import_key !== "default") __rspack_reexport[__rspack_import_key] =() => _cli_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/index.mjs
ADDED
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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/define_property_getters
|
|
13
|
+
(() => {
|
|
14
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
15
|
+
var define = (defs, kind) => {
|
|
16
|
+
for(var key in defs) {
|
|
17
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
define(getters, "get");
|
|
23
|
+
define(values, "value");
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
// webpack/runtime/has_own_property
|
|
27
|
+
(() => {
|
|
28
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
29
|
+
})();
|
|
30
|
+
// webpack/runtime/make_namespace_object
|
|
31
|
+
(() => {
|
|
32
|
+
// define __esModule on exports
|
|
33
|
+
__webpack_require__.r = (exports) => {
|
|
34
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
35
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __webpack_exports__ = {};
|
|
41
|
+
// ESM COMPAT FLAG
|
|
42
|
+
__webpack_require__.r(__webpack_exports__);
|
|
43
|
+
|
|
44
|
+
// EXPORTS
|
|
45
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
46
|
+
"default": () => (/* binding */ src_logger)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
50
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
51
|
+
;// CONCATENATED MODULE: ./src/logger.ts
|
|
52
|
+
|
|
53
|
+
const logger = (0,sdk_namespaceObject.createLogger)('[ Module Federation Rsbuild Plugin ]');
|
|
54
|
+
/* export default */ const src_logger = (logger);
|
|
55
|
+
|
|
56
|
+
exports["default"] = __webpack_exports__["default"];
|
|
57
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
58
|
+
if(["default"].indexOf(__rspack_i) === -1) {
|
|
59
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|