@module-federation/rsbuild-plugin 0.14.3 → 0.15.0
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/constant.cjs.d.ts +1 -0
- package/dist/constant.cjs.js +9 -0
- package/dist/constant.esm.d.ts +1 -0
- package/dist/constant.esm.js +5 -0
- package/dist/index.cjs.js +244 -50
- package/dist/index.esm.js +246 -52
- package/dist/manifest.cjs.d.ts +1 -0
- package/dist/manifest.cjs.js +45 -0
- package/dist/manifest.esm.d.ts +1 -0
- package/dist/manifest.esm.js +43 -0
- package/dist/src/cli/index.d.ts +17 -5
- package/dist/src/cli/manifest.d.ts +5 -0
- package/dist/src/cli/ssr.d.ts +47 -0
- package/dist/src/cli/ssr.spec.d.ts +1 -0
- package/dist/src/utils/addDataFetchExposes.d.ts +2 -0
- package/dist/src/utils/constant.d.ts +2 -0
- package/dist/src/utils/index.d.ts +3 -2
- package/dist/utils.cjs.js +56 -3
- package/dist/utils.esm.js +56 -3
- package/package.json +23 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/utils/constant";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var DEFAULT_ASSET_PREFIX = '/';
|
|
4
|
+
var DATA_FETCH_IDENTIFIER = 'data';
|
|
5
|
+
var DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
6
|
+
|
|
7
|
+
exports.DATA_FETCH_CLIENT_SUFFIX = DATA_FETCH_CLIENT_SUFFIX;
|
|
8
|
+
exports.DATA_FETCH_IDENTIFIER = DATA_FETCH_IDENTIFIER;
|
|
9
|
+
exports.DEFAULT_ASSET_PREFIX = DEFAULT_ASSET_PREFIX;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/utils/constant";
|
package/dist/index.cjs.js
CHANGED
|
@@ -4,7 +4,11 @@ var enhanced = require('@module-federation/enhanced');
|
|
|
4
4
|
var rspack = require('@module-federation/enhanced/rspack');
|
|
5
5
|
var sdk = require('@module-federation/sdk');
|
|
6
6
|
var utils = require('./utils.cjs.js');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var manifest = require('./manifest.cjs.js');
|
|
7
9
|
require('util');
|
|
10
|
+
require('./constant.cjs.js');
|
|
11
|
+
require('fs-extra');
|
|
8
12
|
|
|
9
13
|
var name = "@module-federation/rsbuild-plugin";
|
|
10
14
|
var pkgJson = {
|
|
@@ -12,6 +16,130 @@ var pkgJson = {
|
|
|
12
16
|
|
|
13
17
|
var logger = sdk.createLogger('[ Module Federation Rsbuild Plugin ]');
|
|
14
18
|
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _object_spread(target) {
|
|
33
|
+
for(var i = 1; i < arguments.length; i++){
|
|
34
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
35
|
+
var ownKeys = Object.keys(source);
|
|
36
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
37
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
38
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
ownKeys.forEach(function(key) {
|
|
42
|
+
_define_property(target, key, source[key]);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
function ownKeys(object, enumerableOnly) {
|
|
48
|
+
var keys = Object.keys(object);
|
|
49
|
+
if (Object.getOwnPropertySymbols) {
|
|
50
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
51
|
+
keys.push.apply(keys, symbols);
|
|
52
|
+
}
|
|
53
|
+
return keys;
|
|
54
|
+
}
|
|
55
|
+
function _object_spread_props(target, source) {
|
|
56
|
+
source = source != null ? source : {};
|
|
57
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
58
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
59
|
+
} else {
|
|
60
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
61
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return target;
|
|
65
|
+
}
|
|
66
|
+
var SSR_DIR = 'ssr';
|
|
67
|
+
var SSR_ENV_NAME = 'mf-ssr';
|
|
68
|
+
function setSSREnv() {
|
|
69
|
+
process.env['MF_DISABLE_EMIT_STATS'] = 'true';
|
|
70
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
71
|
+
}
|
|
72
|
+
var isDev = function() {
|
|
73
|
+
return process.env.NODE_ENV === 'development';
|
|
74
|
+
};
|
|
75
|
+
function patchSSRRspackConfig(config, mfConfig) {
|
|
76
|
+
var _config_output, _config_output1;
|
|
77
|
+
var _config;
|
|
78
|
+
if (typeof ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath) !== 'string') {
|
|
79
|
+
throw new Error('publicPath must be string!');
|
|
80
|
+
}
|
|
81
|
+
var publicPath = config.output.publicPath;
|
|
82
|
+
if (publicPath === 'auto') {
|
|
83
|
+
throw new Error('publicPath can not be "auto"!');
|
|
84
|
+
}
|
|
85
|
+
config.output.publicPath = "".concat(config.output.publicPath).concat(SSR_DIR, "/");
|
|
86
|
+
config.target = 'async-node';
|
|
87
|
+
// @module-federation/node/universe-entry-chunk-tracker-plugin only export cjs
|
|
88
|
+
var UniverseEntryChunkTrackerPlugin = require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
89
|
+
(_config = config).plugins || (_config.plugins = []);
|
|
90
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
91
|
+
var uniqueName = mfConfig.name || ((_config_output1 = config.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.uniqueName);
|
|
92
|
+
var chunkFileName = config.output.chunkFilename;
|
|
93
|
+
if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
94
|
+
var suffix = "".concat(sdk.encodeName(uniqueName), "-[chunkhash].js");
|
|
95
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
96
|
+
}
|
|
97
|
+
return config;
|
|
98
|
+
}
|
|
99
|
+
function createSSRREnvConfig(envConfig, mfConfig) {
|
|
100
|
+
var _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1;
|
|
101
|
+
var ssrEnvConfig = _object_spread_props(_object_spread({}, envConfig), {
|
|
102
|
+
tools: {
|
|
103
|
+
rspack: function(config, param) {
|
|
104
|
+
var environment = param.environment;
|
|
105
|
+
if (environment.name !== SSR_ENV_NAME) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
patchSSRRspackConfig(config, mfConfig);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
ssrEnvConfig.output = _object_spread_props(_object_spread({}, ssrEnvConfig.output), {
|
|
113
|
+
// https://rsbuild.rs/config/output/target#other-targets
|
|
114
|
+
// Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
|
|
115
|
+
target: 'node',
|
|
116
|
+
distPath: _object_spread_props(_object_spread({}, (_ssrEnvConfig_output = ssrEnvConfig.output) === null || _ssrEnvConfig_output === void 0 ? void 0 : _ssrEnvConfig_output.distPath), {
|
|
117
|
+
root: path.join(((_ssrEnvConfig_output1 = ssrEnvConfig.output) === null || _ssrEnvConfig_output1 === void 0 ? void 0 : (_ssrEnvConfig_output_distPath = _ssrEnvConfig_output1.distPath) === null || _ssrEnvConfig_output_distPath === void 0 ? void 0 : _ssrEnvConfig_output_distPath.root) || '', SSR_DIR)
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
return ssrEnvConfig;
|
|
121
|
+
}
|
|
122
|
+
function createSSRMFConfig(mfConfig) {
|
|
123
|
+
var _mfConfig_library;
|
|
124
|
+
var _ssrMFConfig;
|
|
125
|
+
var _mfConfig_library_type;
|
|
126
|
+
var ssrMFConfig = _object_spread_props(_object_spread({}, mfConfig), {
|
|
127
|
+
exposes: _object_spread({}, mfConfig.exposes),
|
|
128
|
+
library: _object_spread_props(_object_spread({}, mfConfig.library), {
|
|
129
|
+
name: mfConfig.name,
|
|
130
|
+
type: (_mfConfig_library_type = (_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) !== null && _mfConfig_library_type !== void 0 ? _mfConfig_library_type : 'commonjs-module'
|
|
131
|
+
}),
|
|
132
|
+
dts: false,
|
|
133
|
+
dev: false
|
|
134
|
+
});
|
|
135
|
+
(_ssrMFConfig = ssrMFConfig).runtimePlugins || (_ssrMFConfig.runtimePlugins = []);
|
|
136
|
+
ssrMFConfig.runtimePlugins.push(require.resolve('@module-federation/node/runtimePlugin'));
|
|
137
|
+
if (isDev()) {
|
|
138
|
+
ssrMFConfig.runtimePlugins.push(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
139
|
+
}
|
|
140
|
+
return ssrMFConfig;
|
|
141
|
+
}
|
|
142
|
+
|
|
15
143
|
function _array_like_to_array(arr, len) {
|
|
16
144
|
if (len == null || len > arr.length) len = arr.length;
|
|
17
145
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -42,11 +170,12 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
42
170
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
43
171
|
}
|
|
44
172
|
var RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
45
|
-
var
|
|
173
|
+
var RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
|
|
46
174
|
var LIB_FORMAT = [
|
|
47
175
|
'umd',
|
|
48
176
|
'modern-module'
|
|
49
177
|
];
|
|
178
|
+
var DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
|
|
50
179
|
function isStoryBook(rsbuildConfig) {
|
|
51
180
|
var _rsbuildConfig_plugins;
|
|
52
181
|
if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find(function(p) {
|
|
@@ -58,13 +187,39 @@ function isStoryBook(rsbuildConfig) {
|
|
|
58
187
|
function isMFFormat(bundlerConfig) {
|
|
59
188
|
var _bundlerConfig_output;
|
|
60
189
|
var library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
190
|
+
if (bundlerConfig.name === SSR_ENV_NAME) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
61
193
|
return !((typeof library === "undefined" ? "undefined" : _type_of(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
|
|
62
194
|
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
63
195
|
}
|
|
64
|
-
var
|
|
196
|
+
var isSSRConfig = function(bundlerConfigName) {
|
|
197
|
+
return Boolean(bundlerConfigName === SSR_ENV_NAME);
|
|
198
|
+
};
|
|
199
|
+
var pluginModuleFederation = function(moduleFederationOptions, rsbuildOptions) {
|
|
65
200
|
return {
|
|
66
201
|
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
67
202
|
setup: function(api) {
|
|
203
|
+
var callerName = api.context.callerName;
|
|
204
|
+
var originalRsbuildConfig = api.getRsbuildConfig();
|
|
205
|
+
if (!callerName) {
|
|
206
|
+
throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
207
|
+
}
|
|
208
|
+
var isRslib = callerName === 'rslib';
|
|
209
|
+
var isSSR = Boolean(rsbuildOptions === null || rsbuildOptions === void 0 ? void 0 : rsbuildOptions.ssr);
|
|
210
|
+
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
211
|
+
var _rsbuildConfig_environments;
|
|
212
|
+
if (!isRslib) {
|
|
213
|
+
throw new Error("'ssr' option is only supported in rslib.");
|
|
214
|
+
}
|
|
215
|
+
var rsbuildConfig = api.getRsbuildConfig();
|
|
216
|
+
if (!((_rsbuildConfig_environments = rsbuildConfig.environments) === null || _rsbuildConfig_environments === void 0 ? void 0 : _rsbuildConfig_environments[DEFAULT_MF_ENVIRONMENT_NAME]) || Object.keys(rsbuildConfig.environments).some(function(key) {
|
|
217
|
+
return key.startsWith(DEFAULT_MF_ENVIRONMENT_NAME) && key !== DEFAULT_MF_ENVIRONMENT_NAME;
|
|
218
|
+
})) {
|
|
219
|
+
throw new Error("Please set ".concat(RSBUILD_PLUGIN_NAME, " as global plugin in rslib.config.ts if you set 'ssr:true' ."));
|
|
220
|
+
}
|
|
221
|
+
setSSREnv();
|
|
222
|
+
}
|
|
68
223
|
var sharedOptions = enhanced.parseOptions(moduleFederationOptions.shared || [], function(item, key) {
|
|
69
224
|
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
70
225
|
var config = item === key || !sdk.isRequiredVersion(item) ? {
|
|
@@ -81,6 +236,68 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
81
236
|
var shared = sharedOptions.map(function(shared) {
|
|
82
237
|
return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
|
|
83
238
|
});
|
|
239
|
+
api.modifyRsbuildConfig(function(config) {
|
|
240
|
+
// skip storybook
|
|
241
|
+
if (isStoryBook(config)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
// Change some default configs for remote modules
|
|
245
|
+
if (moduleFederationOptions.exposes) {
|
|
246
|
+
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
247
|
+
var _config, _config1, // Allow remote modules to be loaded by setting CORS headers
|
|
248
|
+
// This is required for MF to work properly across different origins
|
|
249
|
+
_config_server2;
|
|
250
|
+
(_config = config).dev || (_config.dev = {});
|
|
251
|
+
(_config1 = config).server || (_config1.server = {});
|
|
252
|
+
var userConfig = api.getRsbuildConfig('original');
|
|
253
|
+
(_config_server2 = config.server).headers || (_config_server2.headers = {});
|
|
254
|
+
if (!config.server.headers['Access-Control-Allow-Origin'] && !(_type_of((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.cors) === 'object' && userConfig.server.cors.origin)) {
|
|
255
|
+
var corsWarnMsgs = [
|
|
256
|
+
'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.',
|
|
257
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
258
|
+
];
|
|
259
|
+
!isRslib && logger.warn(corsWarnMsgs.join('\n'));
|
|
260
|
+
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
261
|
+
}
|
|
262
|
+
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
263
|
+
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
264
|
+
if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
|
|
265
|
+
var _config_dev;
|
|
266
|
+
(_config_dev = config.dev).client || (_config_dev.client = {});
|
|
267
|
+
config.dev.client.port = config.server.port;
|
|
268
|
+
}
|
|
269
|
+
// Change the default assetPrefix to `true` for remote modules.
|
|
270
|
+
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
271
|
+
var originalConfig = api.getRsbuildConfig('original');
|
|
272
|
+
if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.base)) {
|
|
273
|
+
config.dev.assetPrefix = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (isSSR) {
|
|
277
|
+
var _config_environments, _config_environments1;
|
|
278
|
+
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[SSR_ENV_NAME]) {
|
|
279
|
+
throw new Error("'".concat(SSR_ENV_NAME, "' environment is already defined. Please use another name."));
|
|
280
|
+
}
|
|
281
|
+
config.environments[SSR_ENV_NAME] = createSSRREnvConfig((_config_environments1 = config.environments) === null || _config_environments1 === void 0 ? void 0 : _config_environments1[DEFAULT_MF_ENVIRONMENT_NAME], moduleFederationOptions);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
api.modifyEnvironmentConfig(function(config) {
|
|
285
|
+
// Module Federation runtime uses ES6+ syntax,
|
|
286
|
+
// adding to include and let SWC transform it
|
|
287
|
+
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
288
|
+
/@module-federation[\\/]/
|
|
289
|
+
]);
|
|
290
|
+
return config;
|
|
291
|
+
});
|
|
292
|
+
var generateMergedStatsAndManifestOptions = {
|
|
293
|
+
options: {
|
|
294
|
+
nodePlugin: undefined,
|
|
295
|
+
browserPlugin: undefined,
|
|
296
|
+
distOutputDir: undefined
|
|
297
|
+
},
|
|
298
|
+
isSSRConfig: isSSRConfig
|
|
299
|
+
};
|
|
300
|
+
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
84
301
|
api.onBeforeCreateCompiler(function(param) {
|
|
85
302
|
var bundlerConfigs = param.bundlerConfigs;
|
|
86
303
|
if (!bundlerConfigs) {
|
|
@@ -89,12 +306,14 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
89
306
|
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
90
307
|
if (!isMFFormat(bundlerConfig)) {
|
|
91
308
|
return;
|
|
92
|
-
} else if (isStoryBook(
|
|
309
|
+
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
93
310
|
bundlerConfig.output.uniqueName = "".concat(moduleFederationOptions.name, "-storybook-host");
|
|
94
311
|
} else {
|
|
95
|
-
var _bundlerConfig_optimization, _bundlerConfig_output, _bundlerConfig_output1;
|
|
312
|
+
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1;
|
|
96
313
|
// mf
|
|
97
314
|
utils.autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
315
|
+
utils.addDataFetchExposes(moduleFederationOptions.exposes, isSSRConfig(bundlerConfig.name));
|
|
316
|
+
(_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? true : delete _bundlerConfig_optimization1.runtimeChunk;
|
|
98
317
|
var externals = bundlerConfig.externals;
|
|
99
318
|
if (Array.isArray(externals)) {
|
|
100
319
|
var sharedModules = new Set();
|
|
@@ -152,8 +371,9 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
152
371
|
}
|
|
153
372
|
}
|
|
154
373
|
}
|
|
155
|
-
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal)) {
|
|
374
|
+
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !isSSRConfig(bundlerConfig.name)) {
|
|
156
375
|
bundlerConfig.output.chunkLoading = 'jsonp';
|
|
376
|
+
bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(moduleFederationOptions.name);
|
|
157
377
|
}
|
|
158
378
|
// `uniqueName` is required for react refresh to work
|
|
159
379
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
@@ -162,57 +382,31 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
162
382
|
if (!bundlerConfig.plugins.find(function(p) {
|
|
163
383
|
return p && p.name === rspack.PLUGIN_NAME;
|
|
164
384
|
})) {
|
|
165
|
-
|
|
385
|
+
var _bundlerConfig_output2;
|
|
386
|
+
if (isSSRConfig(bundlerConfig.name)) {
|
|
387
|
+
generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack.ModuleFederationPlugin(createSSRMFConfig(moduleFederationOptions));
|
|
388
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack.ModuleFederationPlugin(moduleFederationOptions);
|
|
392
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = ((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.path) || '';
|
|
393
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
166
394
|
}
|
|
167
395
|
}
|
|
168
396
|
});
|
|
169
397
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (isStoryBook(config)) {
|
|
398
|
+
var generateMergedStatsAndManifest = function() {
|
|
399
|
+
var _generateMergedStatsAndManifestOptions_options = generateMergedStatsAndManifestOptions.options, nodePlugin = _generateMergedStatsAndManifestOptions_options.nodePlugin, browserPlugin = _generateMergedStatsAndManifestOptions_options.browserPlugin, distOutputDir = _generateMergedStatsAndManifestOptions_options.distOutputDir;
|
|
400
|
+
if (!nodePlugin || !browserPlugin || !distOutputDir) {
|
|
174
401
|
return;
|
|
175
402
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// This is required for MF to work properly across different origins
|
|
181
|
-
_config_server2;
|
|
182
|
-
(_config = config).dev || (_config.dev = {});
|
|
183
|
-
(_config1 = config).server || (_config1.server = {});
|
|
184
|
-
var userConfig = api.getRsbuildConfig('original');
|
|
185
|
-
(_config_server2 = config.server).headers || (_config_server2.headers = {});
|
|
186
|
-
if (!config.server.headers['Access-Control-Allow-Origin'] && !(_type_of((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.cors) === 'object' && userConfig.server.cors.origin)) {
|
|
187
|
-
var corsWarnMsgs = [
|
|
188
|
-
'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.',
|
|
189
|
-
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
190
|
-
];
|
|
191
|
-
logger.warn(corsWarnMsgs.join('\n'));
|
|
192
|
-
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
193
|
-
}
|
|
194
|
-
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
195
|
-
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
196
|
-
if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
|
|
197
|
-
var _config_dev;
|
|
198
|
-
(_config_dev = config.dev).client || (_config_dev.client = {});
|
|
199
|
-
config.dev.client.port = config.server.port;
|
|
200
|
-
}
|
|
201
|
-
// Change the default assetPrefix to `true` for remote modules.
|
|
202
|
-
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
203
|
-
var originalConfig = api.getRsbuildConfig('original');
|
|
204
|
-
if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.base)) {
|
|
205
|
-
config.dev.assetPrefix = true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
403
|
+
manifest.updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
404
|
+
};
|
|
405
|
+
api.onDevCompileDone(function() {
|
|
406
|
+
generateMergedStatsAndManifest();
|
|
208
407
|
});
|
|
209
|
-
api.
|
|
210
|
-
|
|
211
|
-
// adding to include and let SWC transform it
|
|
212
|
-
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
213
|
-
/@module-federation[\\/]/
|
|
214
|
-
]);
|
|
215
|
-
return config;
|
|
408
|
+
api.onAfterBuild(function() {
|
|
409
|
+
generateMergedStatsAndManifest();
|
|
216
410
|
});
|
|
217
411
|
}
|
|
218
412
|
};
|
|
@@ -227,6 +421,6 @@ Object.defineProperty(exports, "PLUGIN_NAME", {
|
|
|
227
421
|
get: function () { return rspack.PLUGIN_NAME; }
|
|
228
422
|
});
|
|
229
423
|
exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
|
|
230
|
-
exports.
|
|
424
|
+
exports.SSR_DIR = SSR_DIR;
|
|
231
425
|
exports.isMFFormat = isMFFormat;
|
|
232
426
|
exports.pluginModuleFederation = pluginModuleFederation;
|
package/dist/index.esm.js
CHANGED
|
@@ -2,9 +2,13 @@ import { parseOptions } from '@module-federation/enhanced';
|
|
|
2
2
|
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
3
3
|
import { PLUGIN_NAME, ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
4
|
export { PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
5
|
-
import { createLogger, isRequiredVersion } from '@module-federation/sdk';
|
|
6
|
-
import { autoDeleteSplitChunkCacheGroups, isRegExp } from './utils.esm.js';
|
|
5
|
+
import { createLogger, encodeName, isRequiredVersion } from '@module-federation/sdk';
|
|
6
|
+
import { autoDeleteSplitChunkCacheGroups, addDataFetchExposes, isRegExp } from './utils.esm.js';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { updateStatsAndManifest } from './manifest.esm.js';
|
|
7
9
|
import 'util';
|
|
10
|
+
import './constant.esm.js';
|
|
11
|
+
import 'fs-extra';
|
|
8
12
|
|
|
9
13
|
var name = "@module-federation/rsbuild-plugin";
|
|
10
14
|
var pkgJson = {
|
|
@@ -12,6 +16,130 @@ var pkgJson = {
|
|
|
12
16
|
|
|
13
17
|
var logger = createLogger('[ Module Federation Rsbuild Plugin ]');
|
|
14
18
|
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _object_spread(target) {
|
|
33
|
+
for(var i = 1; i < arguments.length; i++){
|
|
34
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
35
|
+
var ownKeys = Object.keys(source);
|
|
36
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
37
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
38
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
ownKeys.forEach(function(key) {
|
|
42
|
+
_define_property(target, key, source[key]);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
function ownKeys(object, enumerableOnly) {
|
|
48
|
+
var keys = Object.keys(object);
|
|
49
|
+
if (Object.getOwnPropertySymbols) {
|
|
50
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
51
|
+
keys.push.apply(keys, symbols);
|
|
52
|
+
}
|
|
53
|
+
return keys;
|
|
54
|
+
}
|
|
55
|
+
function _object_spread_props(target, source) {
|
|
56
|
+
source = source != null ? source : {};
|
|
57
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
58
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
59
|
+
} else {
|
|
60
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
61
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return target;
|
|
65
|
+
}
|
|
66
|
+
var SSR_DIR = 'ssr';
|
|
67
|
+
var SSR_ENV_NAME = 'mf-ssr';
|
|
68
|
+
function setSSREnv() {
|
|
69
|
+
process.env['MF_DISABLE_EMIT_STATS'] = 'true';
|
|
70
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
71
|
+
}
|
|
72
|
+
var isDev = function() {
|
|
73
|
+
return process.env.NODE_ENV === 'development';
|
|
74
|
+
};
|
|
75
|
+
function patchSSRRspackConfig(config, mfConfig) {
|
|
76
|
+
var _config_output, _config_output1;
|
|
77
|
+
var _config;
|
|
78
|
+
if (typeof ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath) !== 'string') {
|
|
79
|
+
throw new Error('publicPath must be string!');
|
|
80
|
+
}
|
|
81
|
+
var publicPath = config.output.publicPath;
|
|
82
|
+
if (publicPath === 'auto') {
|
|
83
|
+
throw new Error('publicPath can not be "auto"!');
|
|
84
|
+
}
|
|
85
|
+
config.output.publicPath = "".concat(config.output.publicPath).concat(SSR_DIR, "/");
|
|
86
|
+
config.target = 'async-node';
|
|
87
|
+
// @module-federation/node/universe-entry-chunk-tracker-plugin only export cjs
|
|
88
|
+
var UniverseEntryChunkTrackerPlugin = require('@module-federation/node/universe-entry-chunk-tracker-plugin').default;
|
|
89
|
+
(_config = config).plugins || (_config.plugins = []);
|
|
90
|
+
isDev() && config.plugins.push(new UniverseEntryChunkTrackerPlugin());
|
|
91
|
+
var uniqueName = mfConfig.name || ((_config_output1 = config.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.uniqueName);
|
|
92
|
+
var chunkFileName = config.output.chunkFilename;
|
|
93
|
+
if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
94
|
+
var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
|
|
95
|
+
config.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
96
|
+
}
|
|
97
|
+
return config;
|
|
98
|
+
}
|
|
99
|
+
function createSSRREnvConfig(envConfig, mfConfig) {
|
|
100
|
+
var _ssrEnvConfig_output, _ssrEnvConfig_output_distPath, _ssrEnvConfig_output1;
|
|
101
|
+
var ssrEnvConfig = _object_spread_props(_object_spread({}, envConfig), {
|
|
102
|
+
tools: {
|
|
103
|
+
rspack: function(config, param) {
|
|
104
|
+
var environment = param.environment;
|
|
105
|
+
if (environment.name !== SSR_ENV_NAME) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
patchSSRRspackConfig(config, mfConfig);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
ssrEnvConfig.output = _object_spread_props(_object_spread({}, ssrEnvConfig.output), {
|
|
113
|
+
// https://rsbuild.rs/config/output/target#other-targets
|
|
114
|
+
// Rsbuild not support all rspack targets, so modify to async-node in modifyRspackConfig
|
|
115
|
+
target: 'node',
|
|
116
|
+
distPath: _object_spread_props(_object_spread({}, (_ssrEnvConfig_output = ssrEnvConfig.output) === null || _ssrEnvConfig_output === void 0 ? void 0 : _ssrEnvConfig_output.distPath), {
|
|
117
|
+
root: path.join(((_ssrEnvConfig_output1 = ssrEnvConfig.output) === null || _ssrEnvConfig_output1 === void 0 ? void 0 : (_ssrEnvConfig_output_distPath = _ssrEnvConfig_output1.distPath) === null || _ssrEnvConfig_output_distPath === void 0 ? void 0 : _ssrEnvConfig_output_distPath.root) || '', SSR_DIR)
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
return ssrEnvConfig;
|
|
121
|
+
}
|
|
122
|
+
function createSSRMFConfig(mfConfig) {
|
|
123
|
+
var _mfConfig_library;
|
|
124
|
+
var _ssrMFConfig;
|
|
125
|
+
var _mfConfig_library_type;
|
|
126
|
+
var ssrMFConfig = _object_spread_props(_object_spread({}, mfConfig), {
|
|
127
|
+
exposes: _object_spread({}, mfConfig.exposes),
|
|
128
|
+
library: _object_spread_props(_object_spread({}, mfConfig.library), {
|
|
129
|
+
name: mfConfig.name,
|
|
130
|
+
type: (_mfConfig_library_type = (_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) !== null && _mfConfig_library_type !== void 0 ? _mfConfig_library_type : 'commonjs-module'
|
|
131
|
+
}),
|
|
132
|
+
dts: false,
|
|
133
|
+
dev: false
|
|
134
|
+
});
|
|
135
|
+
(_ssrMFConfig = ssrMFConfig).runtimePlugins || (_ssrMFConfig.runtimePlugins = []);
|
|
136
|
+
ssrMFConfig.runtimePlugins.push(require.resolve('@module-federation/node/runtimePlugin'));
|
|
137
|
+
if (isDev()) {
|
|
138
|
+
ssrMFConfig.runtimePlugins.push(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'));
|
|
139
|
+
}
|
|
140
|
+
return ssrMFConfig;
|
|
141
|
+
}
|
|
142
|
+
|
|
15
143
|
function _array_like_to_array(arr, len) {
|
|
16
144
|
if (len == null || len > arr.length) len = arr.length;
|
|
17
145
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -42,11 +170,12 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
42
170
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
43
171
|
}
|
|
44
172
|
var RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
45
|
-
var
|
|
173
|
+
var RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
|
|
46
174
|
var LIB_FORMAT = [
|
|
47
175
|
'umd',
|
|
48
176
|
'modern-module'
|
|
49
177
|
];
|
|
178
|
+
var DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
|
|
50
179
|
function isStoryBook(rsbuildConfig) {
|
|
51
180
|
var _rsbuildConfig_plugins;
|
|
52
181
|
if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find(function(p) {
|
|
@@ -58,13 +187,39 @@ function isStoryBook(rsbuildConfig) {
|
|
|
58
187
|
function isMFFormat(bundlerConfig) {
|
|
59
188
|
var _bundlerConfig_output;
|
|
60
189
|
var library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
190
|
+
if (bundlerConfig.name === SSR_ENV_NAME) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
61
193
|
return !((typeof library === "undefined" ? "undefined" : _type_of(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
|
|
62
194
|
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
63
195
|
}
|
|
64
|
-
var
|
|
196
|
+
var isSSRConfig = function(bundlerConfigName) {
|
|
197
|
+
return Boolean(bundlerConfigName === SSR_ENV_NAME);
|
|
198
|
+
};
|
|
199
|
+
var pluginModuleFederation = function(moduleFederationOptions, rsbuildOptions) {
|
|
65
200
|
return {
|
|
66
201
|
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
67
202
|
setup: function(api) {
|
|
203
|
+
var callerName = api.context.callerName;
|
|
204
|
+
var originalRsbuildConfig = api.getRsbuildConfig();
|
|
205
|
+
if (!callerName) {
|
|
206
|
+
throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
207
|
+
}
|
|
208
|
+
var isRslib = callerName === 'rslib';
|
|
209
|
+
var isSSR = Boolean(rsbuildOptions === null || rsbuildOptions === void 0 ? void 0 : rsbuildOptions.ssr);
|
|
210
|
+
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
211
|
+
var _rsbuildConfig_environments;
|
|
212
|
+
if (!isRslib) {
|
|
213
|
+
throw new Error("'ssr' option is only supported in rslib.");
|
|
214
|
+
}
|
|
215
|
+
var rsbuildConfig = api.getRsbuildConfig();
|
|
216
|
+
if (!((_rsbuildConfig_environments = rsbuildConfig.environments) === null || _rsbuildConfig_environments === void 0 ? void 0 : _rsbuildConfig_environments[DEFAULT_MF_ENVIRONMENT_NAME]) || Object.keys(rsbuildConfig.environments).some(function(key) {
|
|
217
|
+
return key.startsWith(DEFAULT_MF_ENVIRONMENT_NAME) && key !== DEFAULT_MF_ENVIRONMENT_NAME;
|
|
218
|
+
})) {
|
|
219
|
+
throw new Error("Please set ".concat(RSBUILD_PLUGIN_NAME, " as global plugin in rslib.config.ts if you set 'ssr:true' ."));
|
|
220
|
+
}
|
|
221
|
+
setSSREnv();
|
|
222
|
+
}
|
|
68
223
|
var sharedOptions = parseOptions(moduleFederationOptions.shared || [], function(item, key) {
|
|
69
224
|
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
70
225
|
var config = item === key || !isRequiredVersion(item) ? {
|
|
@@ -81,6 +236,68 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
81
236
|
var shared = sharedOptions.map(function(shared) {
|
|
82
237
|
return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
|
|
83
238
|
});
|
|
239
|
+
api.modifyRsbuildConfig(function(config) {
|
|
240
|
+
// skip storybook
|
|
241
|
+
if (isStoryBook(config)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
// Change some default configs for remote modules
|
|
245
|
+
if (moduleFederationOptions.exposes) {
|
|
246
|
+
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
247
|
+
var _config, _config1, // Allow remote modules to be loaded by setting CORS headers
|
|
248
|
+
// This is required for MF to work properly across different origins
|
|
249
|
+
_config_server2;
|
|
250
|
+
(_config = config).dev || (_config.dev = {});
|
|
251
|
+
(_config1 = config).server || (_config1.server = {});
|
|
252
|
+
var userConfig = api.getRsbuildConfig('original');
|
|
253
|
+
(_config_server2 = config.server).headers || (_config_server2.headers = {});
|
|
254
|
+
if (!config.server.headers['Access-Control-Allow-Origin'] && !(_type_of((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.cors) === 'object' && userConfig.server.cors.origin)) {
|
|
255
|
+
var corsWarnMsgs = [
|
|
256
|
+
'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.',
|
|
257
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
258
|
+
];
|
|
259
|
+
!isRslib && logger.warn(corsWarnMsgs.join('\n'));
|
|
260
|
+
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
261
|
+
}
|
|
262
|
+
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
263
|
+
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
264
|
+
if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
|
|
265
|
+
var _config_dev;
|
|
266
|
+
(_config_dev = config.dev).client || (_config_dev.client = {});
|
|
267
|
+
config.dev.client.port = config.server.port;
|
|
268
|
+
}
|
|
269
|
+
// Change the default assetPrefix to `true` for remote modules.
|
|
270
|
+
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
271
|
+
var originalConfig = api.getRsbuildConfig('original');
|
|
272
|
+
if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.base)) {
|
|
273
|
+
config.dev.assetPrefix = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (isSSR) {
|
|
277
|
+
var _config_environments, _config_environments1;
|
|
278
|
+
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[SSR_ENV_NAME]) {
|
|
279
|
+
throw new Error("'".concat(SSR_ENV_NAME, "' environment is already defined. Please use another name."));
|
|
280
|
+
}
|
|
281
|
+
config.environments[SSR_ENV_NAME] = createSSRREnvConfig((_config_environments1 = config.environments) === null || _config_environments1 === void 0 ? void 0 : _config_environments1[DEFAULT_MF_ENVIRONMENT_NAME], moduleFederationOptions);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
api.modifyEnvironmentConfig(function(config) {
|
|
285
|
+
// Module Federation runtime uses ES6+ syntax,
|
|
286
|
+
// adding to include and let SWC transform it
|
|
287
|
+
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
288
|
+
/@module-federation[\\/]/
|
|
289
|
+
]);
|
|
290
|
+
return config;
|
|
291
|
+
});
|
|
292
|
+
var generateMergedStatsAndManifestOptions = {
|
|
293
|
+
options: {
|
|
294
|
+
nodePlugin: undefined,
|
|
295
|
+
browserPlugin: undefined,
|
|
296
|
+
distOutputDir: undefined
|
|
297
|
+
},
|
|
298
|
+
isSSRConfig: isSSRConfig
|
|
299
|
+
};
|
|
300
|
+
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
84
301
|
api.onBeforeCreateCompiler(function(param) {
|
|
85
302
|
var bundlerConfigs = param.bundlerConfigs;
|
|
86
303
|
if (!bundlerConfigs) {
|
|
@@ -89,12 +306,14 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
89
306
|
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
90
307
|
if (!isMFFormat(bundlerConfig)) {
|
|
91
308
|
return;
|
|
92
|
-
} else if (isStoryBook(
|
|
309
|
+
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
93
310
|
bundlerConfig.output.uniqueName = "".concat(moduleFederationOptions.name, "-storybook-host");
|
|
94
311
|
} else {
|
|
95
|
-
var _bundlerConfig_optimization, _bundlerConfig_output, _bundlerConfig_output1;
|
|
312
|
+
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1;
|
|
96
313
|
// mf
|
|
97
314
|
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
315
|
+
addDataFetchExposes(moduleFederationOptions.exposes, isSSRConfig(bundlerConfig.name));
|
|
316
|
+
(_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? true : delete _bundlerConfig_optimization1.runtimeChunk;
|
|
98
317
|
var externals = bundlerConfig.externals;
|
|
99
318
|
if (Array.isArray(externals)) {
|
|
100
319
|
var sharedModules = new Set();
|
|
@@ -152,8 +371,9 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
152
371
|
}
|
|
153
372
|
}
|
|
154
373
|
}
|
|
155
|
-
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal)) {
|
|
374
|
+
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !isSSRConfig(bundlerConfig.name)) {
|
|
156
375
|
bundlerConfig.output.chunkLoading = 'jsonp';
|
|
376
|
+
bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(moduleFederationOptions.name);
|
|
157
377
|
}
|
|
158
378
|
// `uniqueName` is required for react refresh to work
|
|
159
379
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
@@ -162,60 +382,34 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
162
382
|
if (!bundlerConfig.plugins.find(function(p) {
|
|
163
383
|
return p && p.name === PLUGIN_NAME;
|
|
164
384
|
})) {
|
|
165
|
-
|
|
385
|
+
var _bundlerConfig_output2;
|
|
386
|
+
if (isSSRConfig(bundlerConfig.name)) {
|
|
387
|
+
generateMergedStatsAndManifestOptions.options.nodePlugin = new ModuleFederationPlugin(createSSRMFConfig(moduleFederationOptions));
|
|
388
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
generateMergedStatsAndManifestOptions.options.browserPlugin = new ModuleFederationPlugin(moduleFederationOptions);
|
|
392
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = ((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.path) || '';
|
|
393
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
166
394
|
}
|
|
167
395
|
}
|
|
168
396
|
});
|
|
169
397
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (isStoryBook(config)) {
|
|
398
|
+
var generateMergedStatsAndManifest = function() {
|
|
399
|
+
var _generateMergedStatsAndManifestOptions_options = generateMergedStatsAndManifestOptions.options, nodePlugin = _generateMergedStatsAndManifestOptions_options.nodePlugin, browserPlugin = _generateMergedStatsAndManifestOptions_options.browserPlugin, distOutputDir = _generateMergedStatsAndManifestOptions_options.distOutputDir;
|
|
400
|
+
if (!nodePlugin || !browserPlugin || !distOutputDir) {
|
|
174
401
|
return;
|
|
175
402
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// This is required for MF to work properly across different origins
|
|
181
|
-
_config_server2;
|
|
182
|
-
(_config = config).dev || (_config.dev = {});
|
|
183
|
-
(_config1 = config).server || (_config1.server = {});
|
|
184
|
-
var userConfig = api.getRsbuildConfig('original');
|
|
185
|
-
(_config_server2 = config.server).headers || (_config_server2.headers = {});
|
|
186
|
-
if (!config.server.headers['Access-Control-Allow-Origin'] && !(_type_of((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.cors) === 'object' && userConfig.server.cors.origin)) {
|
|
187
|
-
var corsWarnMsgs = [
|
|
188
|
-
'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.',
|
|
189
|
-
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
190
|
-
];
|
|
191
|
-
logger.warn(corsWarnMsgs.join('\n'));
|
|
192
|
-
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
193
|
-
}
|
|
194
|
-
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
195
|
-
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
196
|
-
if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
|
|
197
|
-
var _config_dev;
|
|
198
|
-
(_config_dev = config.dev).client || (_config_dev.client = {});
|
|
199
|
-
config.dev.client.port = config.server.port;
|
|
200
|
-
}
|
|
201
|
-
// Change the default assetPrefix to `true` for remote modules.
|
|
202
|
-
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
203
|
-
var originalConfig = api.getRsbuildConfig('original');
|
|
204
|
-
if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === ((_config_server1 = config.server) === null || _config_server1 === void 0 ? void 0 : _config_server1.base)) {
|
|
205
|
-
config.dev.assetPrefix = true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
403
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
404
|
+
};
|
|
405
|
+
api.onDevCompileDone(function() {
|
|
406
|
+
generateMergedStatsAndManifest();
|
|
208
407
|
});
|
|
209
|
-
api.
|
|
210
|
-
|
|
211
|
-
// adding to include and let SWC transform it
|
|
212
|
-
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
213
|
-
/@module-federation[\\/]/
|
|
214
|
-
]);
|
|
215
|
-
return config;
|
|
408
|
+
api.onAfterBuild(function() {
|
|
409
|
+
generateMergedStatsAndManifest();
|
|
216
410
|
});
|
|
217
411
|
}
|
|
218
412
|
};
|
|
219
413
|
};
|
|
220
414
|
|
|
221
|
-
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
415
|
+
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, SSR_DIR, isMFFormat, pluginModuleFederation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/cli/manifest";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs-extra');
|
|
5
|
+
|
|
6
|
+
function mergeStats(browserStats, nodeStats) {
|
|
7
|
+
var ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
8
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
9
|
+
if ('publicPath' in browserStats.metaData) {
|
|
10
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
11
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
12
|
+
}
|
|
13
|
+
return browserStats;
|
|
14
|
+
}
|
|
15
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
16
|
+
var ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
17
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
18
|
+
if ('publicPath' in browserManifest.metaData) {
|
|
19
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
20
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
21
|
+
}
|
|
22
|
+
return browserManifest;
|
|
23
|
+
}
|
|
24
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
25
|
+
var nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
26
|
+
var browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
27
|
+
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
28
|
+
throw new Error('can not get browserResourceInfo or nodeResourceInfo');
|
|
29
|
+
}
|
|
30
|
+
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
31
|
+
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
32
|
+
return {
|
|
33
|
+
mergedStats: mergedStats,
|
|
34
|
+
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
35
|
+
mergedManifest: mergedManifest,
|
|
36
|
+
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
40
|
+
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
41
|
+
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
42
|
+
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.updateStatsAndManifest = updateStatsAndManifest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/cli/manifest";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
function mergeStats(browserStats, nodeStats) {
|
|
5
|
+
var ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
6
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
7
|
+
if ('publicPath' in browserStats.metaData) {
|
|
8
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
9
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
10
|
+
}
|
|
11
|
+
return browserStats;
|
|
12
|
+
}
|
|
13
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
14
|
+
var ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
15
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
16
|
+
if ('publicPath' in browserManifest.metaData) {
|
|
17
|
+
// @ts-ignore nodeStats has the same structure with browserStats
|
|
18
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
19
|
+
}
|
|
20
|
+
return browserManifest;
|
|
21
|
+
}
|
|
22
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
23
|
+
var nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
24
|
+
var browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
25
|
+
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
26
|
+
throw new Error('can not get browserResourceInfo or nodeResourceInfo');
|
|
27
|
+
}
|
|
28
|
+
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
29
|
+
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
30
|
+
return {
|
|
31
|
+
mergedStats: mergedStats,
|
|
32
|
+
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
33
|
+
mergedManifest: mergedManifest,
|
|
34
|
+
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
38
|
+
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
39
|
+
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
40
|
+
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { updateStatsAndManifest };
|
package/dist/src/cli/index.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
1
|
+
import { ModuleFederationPlugin, PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
2
|
+
import { SSR_DIR } from './ssr';
|
|
2
3
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
4
|
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
|
|
4
5
|
type ModuleFederationOptions = moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
5
|
-
|
|
6
|
+
type RSBUILD_PLUGIN_OPTIONS = {
|
|
7
|
+
ssr?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type ExposedAPIType = {
|
|
10
|
+
options: {
|
|
11
|
+
nodePlugin?: ModuleFederationPlugin;
|
|
12
|
+
browserPlugin?: ModuleFederationPlugin;
|
|
13
|
+
distOutputDir?: string;
|
|
14
|
+
};
|
|
15
|
+
isSSRConfig: typeof isSSRConfig;
|
|
16
|
+
};
|
|
17
|
+
export type { ModuleFederationOptions, ExposedAPIType };
|
|
6
18
|
declare const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = "rsbuild:module-federation-enhanced";
|
|
7
|
-
|
|
8
|
-
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, RSPACK_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, };
|
|
19
|
+
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, SSR_DIR };
|
|
9
20
|
export declare function isMFFormat(bundlerConfig: Rspack.Configuration): boolean;
|
|
10
|
-
|
|
21
|
+
declare const isSSRConfig: (bundlerConfigName?: string) => boolean;
|
|
22
|
+
export declare const pluginModuleFederation: (moduleFederationOptions: ModuleFederationOptions, rsbuildOptions?: RSBUILD_PLUGIN_OPTIONS) => RsbuildPlugin;
|
|
11
23
|
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
|
|
2
|
+
import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
3
|
+
type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|
|
4
|
+
export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { EnvironmentConfig, Rspack } 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 function setSSREnv(): void;
|
|
6
|
+
export declare function patchSSRRspackConfig(config: Rspack.Configuration, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): Rspack.RspackOptions;
|
|
7
|
+
export declare function createSSRREnvConfig(envConfig: EnvironmentConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): EnvironmentConfig;
|
|
8
|
+
export declare function createSSRMFConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): {
|
|
9
|
+
exposes: {};
|
|
10
|
+
library: {
|
|
11
|
+
name: string | undefined;
|
|
12
|
+
type: string;
|
|
13
|
+
amdContainer?: moduleFederationPlugin.AmdContainer;
|
|
14
|
+
auxiliaryComment?: moduleFederationPlugin.AuxiliaryComment;
|
|
15
|
+
export?: moduleFederationPlugin.LibraryExport;
|
|
16
|
+
umdNamedDefine?: moduleFederationPlugin.UmdNamedDefine;
|
|
17
|
+
};
|
|
18
|
+
dts: boolean;
|
|
19
|
+
dev: boolean;
|
|
20
|
+
filename?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
remoteType?: moduleFederationPlugin.ExternalsType;
|
|
23
|
+
remotes?: moduleFederationPlugin.Remotes;
|
|
24
|
+
runtime?: moduleFederationPlugin.EntryRuntime;
|
|
25
|
+
shareScope?: string | string[];
|
|
26
|
+
shareStrategy?: moduleFederationPlugin.SharedStrategy;
|
|
27
|
+
shared?: moduleFederationPlugin.Shared;
|
|
28
|
+
runtimePlugins?: string[];
|
|
29
|
+
getPublicPath?: string;
|
|
30
|
+
implementation?: string;
|
|
31
|
+
manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
|
|
32
|
+
dataPrefetch?: moduleFederationPlugin.DataPrefetch;
|
|
33
|
+
virtualRuntimeEntry?: boolean;
|
|
34
|
+
experiments?: {
|
|
35
|
+
externalRuntime?: boolean;
|
|
36
|
+
provideExternalRuntime?: boolean;
|
|
37
|
+
asyncStartup?: boolean;
|
|
38
|
+
optimization?: {
|
|
39
|
+
disableSnapshot?: boolean;
|
|
40
|
+
target?: "web" | "node";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
bridge?: {
|
|
44
|
+
disableAlias?: boolean;
|
|
45
|
+
};
|
|
46
|
+
async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function isRegExp(target: any): target is RegExp;
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export { DEFAULT_ASSET_PREFIX } from './constant';
|
|
3
|
+
export { autoDeleteSplitChunkCacheGroups } from './autoDeleteSplitChunkCacheGroups';
|
|
4
|
+
export { addDataFetchExposes } from './addDataFetchExposes';
|
package/dist/utils.cjs.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var util = require('util');
|
|
4
|
-
|
|
5
|
-
var
|
|
4
|
+
var constant = require('./constant.cjs.js');
|
|
5
|
+
var fs = require('fs-extra');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var sdk = require('@module-federation/sdk');
|
|
6
8
|
|
|
7
9
|
// lib-polyfill.js: include core-js,@babel/runtime,@swc/helpers,tslib.
|
|
8
10
|
// lib-react.js: include react,react-dom.
|
|
@@ -71,10 +73,61 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
|
|
|
71
73
|
return splitChunks;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
function _type_of(obj) {
|
|
77
|
+
"@swc/helpers - typeof";
|
|
78
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
79
|
+
}
|
|
80
|
+
var addDataFetchExpose = function(exposes, key, filepath) {
|
|
81
|
+
var suffix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
82
|
+
if (!fs.existsSync(filepath)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
var dataFetchKey = key === '.' ? "./".concat(constant.DATA_FETCH_IDENTIFIER).concat(suffix) : "".concat(key, ".").concat(constant.DATA_FETCH_IDENTIFIER).concat(suffix);
|
|
86
|
+
if (exposes[dataFetchKey] && exposes[dataFetchKey] !== filepath) {
|
|
87
|
+
throw new Error("data fetch key ".concat(dataFetchKey, " already exists, please modify this expose key, do not end with '").concat(constant.DATA_FETCH_IDENTIFIER, "' or '").concat(constant.DATA_FETCH_CLIENT_SUFFIX, "'"));
|
|
88
|
+
}
|
|
89
|
+
exposes[dataFetchKey] = filepath;
|
|
90
|
+
return dataFetchKey;
|
|
91
|
+
};
|
|
92
|
+
var addExcludeDtsSuffix = function(filepath) {
|
|
93
|
+
return "".concat(filepath, "?exclude-mf-dts=true");
|
|
94
|
+
};
|
|
95
|
+
function addDataFetchExposes(exposes, isServer) {
|
|
96
|
+
if ((typeof exposes === "undefined" ? "undefined" : _type_of(exposes)) !== 'object' || Array.isArray(exposes)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (Object.keys(exposes).length === 0) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
var tempDataFetchFilepath = path.resolve(process.cwd(), "node_modules/".concat(sdk.TEMP_DIR, "/data-fetch-fallback.ts"));
|
|
103
|
+
var content = "export const fetchData=()=>{throw new Error('should not be called')};";
|
|
104
|
+
fs.ensureDirSync(path.dirname(tempDataFetchFilepath));
|
|
105
|
+
fs.writeFileSync(tempDataFetchFilepath, content);
|
|
106
|
+
Object.keys(exposes).forEach(function(key) {
|
|
107
|
+
var expose = exposes[key];
|
|
108
|
+
if (typeof expose !== 'string') {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
var absPath = path.resolve(process.cwd(), expose);
|
|
112
|
+
var dataFetchPath = "".concat(absPath.replace(path.extname(absPath), ''), ".").concat(constant.DATA_FETCH_IDENTIFIER, ".ts");
|
|
113
|
+
var dataFetchClientPath = "".concat(absPath.replace(path.extname(absPath), ''), ".").concat(constant.DATA_FETCH_IDENTIFIER, ".client.ts");
|
|
114
|
+
var dateFetchClientKey = addDataFetchExpose(exposes, key, dataFetchClientPath, constant.DATA_FETCH_CLIENT_SUFFIX);
|
|
115
|
+
if (!isServer && dateFetchClientKey) {
|
|
116
|
+
exposes[dateFetchClientKey.replace(constant.DATA_FETCH_CLIENT_SUFFIX, '')] = addExcludeDtsSuffix(tempDataFetchFilepath);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
var dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
|
|
120
|
+
if (dataFetchKey && fs.existsSync(dataFetchClientPath)) {
|
|
121
|
+
exposes["".concat(dataFetchKey).concat(constant.DATA_FETCH_CLIENT_SUFFIX)] = addExcludeDtsSuffix(tempDataFetchFilepath);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
74
126
|
function isRegExp(target) {
|
|
75
127
|
return util.types.isRegExp(target);
|
|
76
128
|
}
|
|
77
129
|
|
|
78
|
-
exports.DEFAULT_ASSET_PREFIX = DEFAULT_ASSET_PREFIX;
|
|
130
|
+
exports.DEFAULT_ASSET_PREFIX = constant.DEFAULT_ASSET_PREFIX;
|
|
131
|
+
exports.addDataFetchExposes = addDataFetchExposes;
|
|
79
132
|
exports.autoDeleteSplitChunkCacheGroups = autoDeleteSplitChunkCacheGroups;
|
|
80
133
|
exports.isRegExp = isRegExp;
|
package/dist/utils.esm.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import util from 'util';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { DATA_FETCH_IDENTIFIER, DATA_FETCH_CLIENT_SUFFIX } from './constant.esm.js';
|
|
3
|
+
export { DEFAULT_ASSET_PREFIX } from './constant.esm.js';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { TEMP_DIR } from '@module-federation/sdk';
|
|
4
7
|
|
|
5
8
|
// lib-polyfill.js: include core-js,@babel/runtime,@swc/helpers,tslib.
|
|
6
9
|
// lib-react.js: include react,react-dom.
|
|
@@ -69,8 +72,58 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
|
|
|
69
72
|
return splitChunks;
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
function _type_of(obj) {
|
|
76
|
+
"@swc/helpers - typeof";
|
|
77
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
78
|
+
}
|
|
79
|
+
var addDataFetchExpose = function(exposes, key, filepath) {
|
|
80
|
+
var suffix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
81
|
+
if (!fs.existsSync(filepath)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
var dataFetchKey = key === '.' ? "./".concat(DATA_FETCH_IDENTIFIER).concat(suffix) : "".concat(key, ".").concat(DATA_FETCH_IDENTIFIER).concat(suffix);
|
|
85
|
+
if (exposes[dataFetchKey] && exposes[dataFetchKey] !== filepath) {
|
|
86
|
+
throw new Error("data fetch key ".concat(dataFetchKey, " already exists, please modify this expose key, do not end with '").concat(DATA_FETCH_IDENTIFIER, "' or '").concat(DATA_FETCH_CLIENT_SUFFIX, "'"));
|
|
87
|
+
}
|
|
88
|
+
exposes[dataFetchKey] = filepath;
|
|
89
|
+
return dataFetchKey;
|
|
90
|
+
};
|
|
91
|
+
var addExcludeDtsSuffix = function(filepath) {
|
|
92
|
+
return "".concat(filepath, "?exclude-mf-dts=true");
|
|
93
|
+
};
|
|
94
|
+
function addDataFetchExposes(exposes, isServer) {
|
|
95
|
+
if ((typeof exposes === "undefined" ? "undefined" : _type_of(exposes)) !== 'object' || Array.isArray(exposes)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(exposes).length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
var tempDataFetchFilepath = path.resolve(process.cwd(), "node_modules/".concat(TEMP_DIR, "/data-fetch-fallback.ts"));
|
|
102
|
+
var content = "export const fetchData=()=>{throw new Error('should not be called')};";
|
|
103
|
+
fs.ensureDirSync(path.dirname(tempDataFetchFilepath));
|
|
104
|
+
fs.writeFileSync(tempDataFetchFilepath, content);
|
|
105
|
+
Object.keys(exposes).forEach(function(key) {
|
|
106
|
+
var expose = exposes[key];
|
|
107
|
+
if (typeof expose !== 'string') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
var absPath = path.resolve(process.cwd(), expose);
|
|
111
|
+
var dataFetchPath = "".concat(absPath.replace(path.extname(absPath), ''), ".").concat(DATA_FETCH_IDENTIFIER, ".ts");
|
|
112
|
+
var dataFetchClientPath = "".concat(absPath.replace(path.extname(absPath), ''), ".").concat(DATA_FETCH_IDENTIFIER, ".client.ts");
|
|
113
|
+
var dateFetchClientKey = addDataFetchExpose(exposes, key, dataFetchClientPath, DATA_FETCH_CLIENT_SUFFIX);
|
|
114
|
+
if (!isServer && dateFetchClientKey) {
|
|
115
|
+
exposes[dateFetchClientKey.replace(DATA_FETCH_CLIENT_SUFFIX, '')] = addExcludeDtsSuffix(tempDataFetchFilepath);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
|
|
119
|
+
if (dataFetchKey && fs.existsSync(dataFetchClientPath)) {
|
|
120
|
+
exposes["".concat(dataFetchKey).concat(DATA_FETCH_CLIENT_SUFFIX)] = addExcludeDtsSuffix(tempDataFetchFilepath);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
72
125
|
function isRegExp(target) {
|
|
73
126
|
return util.types.isRegExp(target);
|
|
74
127
|
}
|
|
75
128
|
|
|
76
|
-
export {
|
|
129
|
+
export { addDataFetchExposes, autoDeleteSplitChunkCacheGroups, isRegExp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/rsbuild-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Module Federation plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://module-federation.io",
|
|
6
6
|
"bugs": {
|
|
@@ -22,6 +22,16 @@
|
|
|
22
22
|
"types": "./dist/utils.cjs.d.ts",
|
|
23
23
|
"import": "./dist/utils.esm.js",
|
|
24
24
|
"require": "./dist/utils.cjs.js"
|
|
25
|
+
},
|
|
26
|
+
"./constant": {
|
|
27
|
+
"types": "./dist/constant.cjs.d.ts",
|
|
28
|
+
"import": "./dist/constant.esm.js",
|
|
29
|
+
"require": "./dist/constant.cjs.js"
|
|
30
|
+
},
|
|
31
|
+
"./manifest": {
|
|
32
|
+
"types": "./dist/manifest.cjs.d.ts",
|
|
33
|
+
"import": "./dist/manifest.esm.js",
|
|
34
|
+
"require": "./dist/manifest.cjs.js"
|
|
25
35
|
}
|
|
26
36
|
},
|
|
27
37
|
"main": "./dist/index.cjs.js",
|
|
@@ -33,6 +43,12 @@
|
|
|
33
43
|
],
|
|
34
44
|
"utils": [
|
|
35
45
|
"./dist/utils.cjs.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"constant": [
|
|
48
|
+
"./dist/constant.cjs.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"manifest": [
|
|
51
|
+
"./dist/manifest.cjs.d.ts"
|
|
36
52
|
]
|
|
37
53
|
}
|
|
38
54
|
},
|
|
@@ -40,14 +56,16 @@
|
|
|
40
56
|
"dist"
|
|
41
57
|
],
|
|
42
58
|
"dependencies": {
|
|
43
|
-
"
|
|
44
|
-
"@module-federation/
|
|
59
|
+
"fs-extra": "11.3.0",
|
|
60
|
+
"@module-federation/sdk": "0.15.0",
|
|
61
|
+
"@module-federation/enhanced": "0.15.0",
|
|
62
|
+
"@module-federation/node": "2.7.7"
|
|
45
63
|
},
|
|
46
64
|
"devDependencies": {
|
|
47
|
-
"@rsbuild/core": "^1.3.
|
|
65
|
+
"@rsbuild/core": "^1.3.21"
|
|
48
66
|
},
|
|
49
67
|
"peerDependencies": {
|
|
50
|
-
"@rsbuild/core": "1.
|
|
68
|
+
"@rsbuild/core": "^1.3.21"
|
|
51
69
|
},
|
|
52
70
|
"peerDependenciesMeta": {
|
|
53
71
|
"@rsbuild/core": {
|