@module-federation/rsbuild-plugin 0.14.3 → 0.16.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 +18 -0
- package/dist/constant.esm.d.ts +1 -0
- package/dist/constant.esm.mjs +11 -0
- package/dist/index.cjs.js +194 -55
- package/dist/{index.esm.js → index.esm.mjs} +192 -53
- package/dist/src/cli/index.d.ts +23 -6
- package/dist/src/constant.d.ts +9 -0
- package/dist/src/utils/addDataFetchExposes.d.ts +2 -0
- package/dist/src/utils/index.d.ts +5 -2
- package/dist/src/utils/manifest.d.ts +5 -0
- package/dist/src/utils/ssr.d.ts +47 -0
- package/dist/src/utils/ssr.spec.d.ts +1 -0
- package/dist/utils.cjs.js +265 -3
- package/dist/utils.esm.mjs +330 -0
- package/package.json +18 -8
- package/dist/src/utils/constant.d.ts +0 -1
- package/dist/utils.esm.js +0 -76
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/constant";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var DEFAULT_ASSET_PREFIX = '/';
|
|
4
|
+
var DATA_FETCH_IDENTIFIER = 'data';
|
|
5
|
+
var DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
6
|
+
var CALL_NAME_MAP = {
|
|
7
|
+
RSPRESS: 'rspress',
|
|
8
|
+
RSLIB: 'rslib'
|
|
9
|
+
};
|
|
10
|
+
var RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
11
|
+
var RSPRESS_SSR_DIR = 'ssr';
|
|
12
|
+
|
|
13
|
+
exports.CALL_NAME_MAP = CALL_NAME_MAP;
|
|
14
|
+
exports.DATA_FETCH_CLIENT_SUFFIX = DATA_FETCH_CLIENT_SUFFIX;
|
|
15
|
+
exports.DATA_FETCH_IDENTIFIER = DATA_FETCH_IDENTIFIER;
|
|
16
|
+
exports.DEFAULT_ASSET_PREFIX = DEFAULT_ASSET_PREFIX;
|
|
17
|
+
exports.RSPRESS_BUNDLER_CONFIG_NAME = RSPRESS_BUNDLER_CONFIG_NAME;
|
|
18
|
+
exports.RSPRESS_SSR_DIR = RSPRESS_SSR_DIR;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/constant";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var DEFAULT_ASSET_PREFIX = '/';
|
|
2
|
+
var DATA_FETCH_IDENTIFIER = 'data';
|
|
3
|
+
var DATA_FETCH_CLIENT_SUFFIX = '.client';
|
|
4
|
+
var CALL_NAME_MAP = {
|
|
5
|
+
RSPRESS: 'rspress',
|
|
6
|
+
RSLIB: 'rslib'
|
|
7
|
+
};
|
|
8
|
+
var RSPRESS_BUNDLER_CONFIG_NAME = 'node';
|
|
9
|
+
var RSPRESS_SSR_DIR = 'ssr';
|
|
10
|
+
|
|
11
|
+
export { CALL_NAME_MAP, DATA_FETCH_CLIENT_SUFFIX, DATA_FETCH_IDENTIFIER, DEFAULT_ASSET_PREFIX, RSPRESS_BUNDLER_CONFIG_NAME, RSPRESS_SSR_DIR };
|
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 constant = require('./constant.cjs.js');
|
|
7
8
|
require('util');
|
|
9
|
+
require('fs-extra');
|
|
10
|
+
require('path');
|
|
11
|
+
require('node:module');
|
|
8
12
|
|
|
9
13
|
var name = "@module-federation/rsbuild-plugin";
|
|
10
14
|
var pkgJson = {
|
|
@@ -20,12 +24,59 @@ function _array_like_to_array(arr, len) {
|
|
|
20
24
|
function _array_without_holes(arr) {
|
|
21
25
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
22
26
|
}
|
|
27
|
+
function _define_property(obj, key, value) {
|
|
28
|
+
if (key in obj) {
|
|
29
|
+
Object.defineProperty(obj, key, {
|
|
30
|
+
value: value,
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
obj[key] = value;
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
23
40
|
function _iterable_to_array(iter) {
|
|
24
41
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
25
42
|
}
|
|
26
43
|
function _non_iterable_spread() {
|
|
27
44
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
28
45
|
}
|
|
46
|
+
function _object_spread(target) {
|
|
47
|
+
for(var i = 1; i < arguments.length; i++){
|
|
48
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
49
|
+
var ownKeys = Object.keys(source);
|
|
50
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
51
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
52
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
ownKeys.forEach(function(key) {
|
|
56
|
+
_define_property(target, key, source[key]);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return target;
|
|
60
|
+
}
|
|
61
|
+
function ownKeys(object, enumerableOnly) {
|
|
62
|
+
var keys = Object.keys(object);
|
|
63
|
+
if (Object.getOwnPropertySymbols) {
|
|
64
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
65
|
+
keys.push.apply(keys, symbols);
|
|
66
|
+
}
|
|
67
|
+
return keys;
|
|
68
|
+
}
|
|
69
|
+
function _object_spread_props(target, source) {
|
|
70
|
+
source = source != null ? source : {};
|
|
71
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
72
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
73
|
+
} else {
|
|
74
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
75
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
29
80
|
function _to_consumable_array(arr) {
|
|
30
81
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
31
82
|
}
|
|
@@ -42,11 +93,12 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
42
93
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
43
94
|
}
|
|
44
95
|
var RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
45
|
-
var
|
|
96
|
+
var RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
|
|
46
97
|
var LIB_FORMAT = [
|
|
47
98
|
'umd',
|
|
48
99
|
'modern-module'
|
|
49
100
|
];
|
|
101
|
+
var DEFAULT_MF_ENVIRONMENT_NAME = 'mf';
|
|
50
102
|
function isStoryBook(rsbuildConfig) {
|
|
51
103
|
var _rsbuildConfig_plugins;
|
|
52
104
|
if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find(function(p) {
|
|
@@ -58,13 +110,44 @@ function isStoryBook(rsbuildConfig) {
|
|
|
58
110
|
function isMFFormat(bundlerConfig) {
|
|
59
111
|
var _bundlerConfig_output;
|
|
60
112
|
var library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
113
|
+
if (bundlerConfig.name === utils.SSR_ENV_NAME) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
61
116
|
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
117
|
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
63
118
|
}
|
|
64
|
-
var
|
|
119
|
+
var isSSRConfig = function(bundlerConfigName) {
|
|
120
|
+
return Boolean(bundlerConfigName === utils.SSR_ENV_NAME);
|
|
121
|
+
};
|
|
122
|
+
var isRspressSSGConfig = function(bundlerConfigName) {
|
|
123
|
+
return bundlerConfigName === constant.RSPRESS_BUNDLER_CONFIG_NAME;
|
|
124
|
+
};
|
|
125
|
+
var pluginModuleFederation = function(moduleFederationOptions, rsbuildOptions) {
|
|
65
126
|
return {
|
|
66
127
|
name: RSBUILD_PLUGIN_MODULE_FEDERATION_NAME,
|
|
67
128
|
setup: function(api) {
|
|
129
|
+
var _ref = rsbuildOptions || {}, _ref_ssr = _ref.ssr, ssr = _ref_ssr === void 0 ? undefined : _ref_ssr, _ref_ssrDir = _ref.ssrDir, ssrDir = _ref_ssrDir === void 0 ? utils.SSR_DIR : _ref_ssrDir, _ref_environment = _ref.environment, environment = _ref_environment === void 0 ? DEFAULT_MF_ENVIRONMENT_NAME : _ref_environment;
|
|
130
|
+
var callerName = api.context.callerName;
|
|
131
|
+
var originalRsbuildConfig = api.getRsbuildConfig();
|
|
132
|
+
if (!callerName) {
|
|
133
|
+
throw new Error('`callerName` is undefined. Please ensure the @rsbuild/core version is higher than 1.3.21 .');
|
|
134
|
+
}
|
|
135
|
+
var isRslib = callerName === constant.CALL_NAME_MAP.RSLIB;
|
|
136
|
+
var isRspress = callerName === constant.CALL_NAME_MAP.RSPRESS;
|
|
137
|
+
var isSSR = Boolean(ssr);
|
|
138
|
+
if (isSSR && !isStoryBook(originalRsbuildConfig)) {
|
|
139
|
+
var _rsbuildConfig_environments;
|
|
140
|
+
if (!isRslib && !isRspress) {
|
|
141
|
+
throw new Error("'ssr' option is only supported in rslib.");
|
|
142
|
+
}
|
|
143
|
+
var rsbuildConfig = api.getRsbuildConfig();
|
|
144
|
+
if (!((_rsbuildConfig_environments = rsbuildConfig.environments) === null || _rsbuildConfig_environments === void 0 ? void 0 : _rsbuildConfig_environments[environment]) || Object.keys(rsbuildConfig.environments).some(function(key) {
|
|
145
|
+
return key.startsWith(environment) && key !== environment;
|
|
146
|
+
})) {
|
|
147
|
+
throw new Error("Please set ".concat(RSBUILD_PLUGIN_NAME, " as global plugin in rslib.config.ts if you set 'ssr:true' ."));
|
|
148
|
+
}
|
|
149
|
+
utils.setSSREnv();
|
|
150
|
+
}
|
|
68
151
|
var sharedOptions = enhanced.parseOptions(moduleFederationOptions.shared || [], function(item, key) {
|
|
69
152
|
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
70
153
|
var config = item === key || !sdk.isRequiredVersion(item) ? {
|
|
@@ -81,20 +164,85 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
81
164
|
var shared = sharedOptions.map(function(shared) {
|
|
82
165
|
return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
|
|
83
166
|
});
|
|
167
|
+
api.modifyRsbuildConfig(function(config) {
|
|
168
|
+
// skip storybook
|
|
169
|
+
if (isStoryBook(config)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Change some default configs for remote modules
|
|
173
|
+
if (moduleFederationOptions.exposes) {
|
|
174
|
+
var _userConfig_server, _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
175
|
+
var _config, _config1, // Allow remote modules to be loaded by setting CORS headers
|
|
176
|
+
// This is required for MF to work properly across different origins
|
|
177
|
+
_config_server2;
|
|
178
|
+
(_config = config).dev || (_config.dev = {});
|
|
179
|
+
(_config1 = config).server || (_config1.server = {});
|
|
180
|
+
var userConfig = api.getRsbuildConfig('original');
|
|
181
|
+
(_config_server2 = config.server).headers || (_config_server2.headers = {});
|
|
182
|
+
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)) {
|
|
183
|
+
var corsWarnMsgs = [
|
|
184
|
+
'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.',
|
|
185
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
186
|
+
];
|
|
187
|
+
!isRslib && !isRspress && logger.warn(corsWarnMsgs.join('\n'));
|
|
188
|
+
config.server.headers['Access-Control-Allow-Origin'] = '*';
|
|
189
|
+
}
|
|
190
|
+
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
|
|
191
|
+
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.
|
|
192
|
+
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)) {
|
|
193
|
+
var _config_dev;
|
|
194
|
+
(_config_dev = config.dev).client || (_config_dev.client = {});
|
|
195
|
+
config.dev.client.port = config.server.port;
|
|
196
|
+
}
|
|
197
|
+
// Change the default assetPrefix to `true` for remote modules.
|
|
198
|
+
// This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
|
|
199
|
+
var originalConfig = api.getRsbuildConfig('original');
|
|
200
|
+
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)) {
|
|
201
|
+
config.dev.assetPrefix = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (isSSR) {
|
|
205
|
+
var _config_environments, _config_environments1;
|
|
206
|
+
if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[utils.SSR_ENV_NAME]) {
|
|
207
|
+
throw new Error("'".concat(utils.SSR_ENV_NAME, "' environment is already defined. Please use another name."));
|
|
208
|
+
}
|
|
209
|
+
config.environments[utils.SSR_ENV_NAME] = utils.createSSRREnvConfig((_config_environments1 = config.environments) === null || _config_environments1 === void 0 ? void 0 : _config_environments1[environment], moduleFederationOptions, ssrDir, config, callerName);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
api.modifyEnvironmentConfig(function(config) {
|
|
213
|
+
// Module Federation runtime uses ES6+ syntax,
|
|
214
|
+
// adding to include and let SWC transform it
|
|
215
|
+
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
216
|
+
/@module-federation[\\/]/
|
|
217
|
+
]);
|
|
218
|
+
return config;
|
|
219
|
+
});
|
|
220
|
+
var generateMergedStatsAndManifestOptions = {
|
|
221
|
+
options: {
|
|
222
|
+
nodePlugin: undefined,
|
|
223
|
+
browserPlugin: undefined,
|
|
224
|
+
distOutputDir: undefined
|
|
225
|
+
},
|
|
226
|
+
isSSRConfig: isSSRConfig,
|
|
227
|
+
isRspressSSGConfig: isRspressSSGConfig
|
|
228
|
+
};
|
|
229
|
+
api.expose(RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, generateMergedStatsAndManifestOptions);
|
|
84
230
|
api.onBeforeCreateCompiler(function(param) {
|
|
85
231
|
var bundlerConfigs = param.bundlerConfigs;
|
|
86
232
|
if (!bundlerConfigs) {
|
|
87
233
|
throw new Error('Can not get bundlerConfigs!');
|
|
88
234
|
}
|
|
89
235
|
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
90
|
-
if (!isMFFormat(bundlerConfig)) {
|
|
236
|
+
if (!isMFFormat(bundlerConfig) && !isRspress) {
|
|
91
237
|
return;
|
|
92
|
-
} else if (isStoryBook(
|
|
238
|
+
} else if (isStoryBook(originalRsbuildConfig)) {
|
|
93
239
|
bundlerConfig.output.uniqueName = "".concat(moduleFederationOptions.name, "-storybook-host");
|
|
94
240
|
} else {
|
|
95
|
-
var _bundlerConfig_optimization, _bundlerConfig_output, _bundlerConfig_output1;
|
|
241
|
+
var _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _bundlerConfig_output1;
|
|
96
242
|
// mf
|
|
97
243
|
utils.autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
244
|
+
utils.addDataFetchExposes(moduleFederationOptions.exposes, isSSRConfig(bundlerConfig.name));
|
|
245
|
+
(_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? true : delete _bundlerConfig_optimization1.runtimeChunk;
|
|
98
246
|
var externals = bundlerConfig.externals;
|
|
99
247
|
if (Array.isArray(externals)) {
|
|
100
248
|
var sharedModules = new Set();
|
|
@@ -152,8 +300,9 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
152
300
|
}
|
|
153
301
|
}
|
|
154
302
|
}
|
|
155
|
-
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal)) {
|
|
303
|
+
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal) && !isSSRConfig(bundlerConfig.name) && !isRspressSSGConfig(bundlerConfig.name)) {
|
|
156
304
|
bundlerConfig.output.chunkLoading = 'jsonp';
|
|
305
|
+
bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(moduleFederationOptions.name);
|
|
157
306
|
}
|
|
158
307
|
// `uniqueName` is required for react refresh to work
|
|
159
308
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
@@ -162,71 +311,61 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
162
311
|
if (!bundlerConfig.plugins.find(function(p) {
|
|
163
312
|
return p && p.name === rspack.PLUGIN_NAME;
|
|
164
313
|
})) {
|
|
165
|
-
|
|
314
|
+
var _bundlerConfig_output2;
|
|
315
|
+
if (isSSRConfig(bundlerConfig.name)) {
|
|
316
|
+
generateMergedStatsAndManifestOptions.options.nodePlugin = new rspack.ModuleFederationPlugin(utils.createSSRMFConfig(moduleFederationOptions));
|
|
317
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.nodePlugin);
|
|
318
|
+
return;
|
|
319
|
+
} else if (isRspressSSGConfig(bundlerConfig.name)) {
|
|
320
|
+
var _bundlerConfig;
|
|
321
|
+
var mfConfig = _object_spread_props(_object_spread({}, utils.createSSRMFConfig(moduleFederationOptions)), {
|
|
322
|
+
// expose in mf-ssg env
|
|
323
|
+
exposes: {},
|
|
324
|
+
manifest: false,
|
|
325
|
+
library: undefined
|
|
326
|
+
});
|
|
327
|
+
utils.patchSSRRspackConfig(bundlerConfig, mfConfig, constant.RSPRESS_SSR_DIR, callerName, false, false);
|
|
328
|
+
(_bundlerConfig = bundlerConfig).output || (_bundlerConfig.output = {});
|
|
329
|
+
bundlerConfig.output.publicPath = '/';
|
|
330
|
+
// MF depend on asyncChunks
|
|
331
|
+
bundlerConfig.output.asyncChunks = undefined;
|
|
332
|
+
generateMergedStatsAndManifestOptions.options.rspressSSGPlugin = new rspack.ModuleFederationPlugin(mfConfig);
|
|
333
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.rspressSSGPlugin);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
generateMergedStatsAndManifestOptions.options.browserPlugin = new rspack.ModuleFederationPlugin(moduleFederationOptions);
|
|
337
|
+
generateMergedStatsAndManifestOptions.options.distOutputDir = ((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.path) || '';
|
|
338
|
+
bundlerConfig.plugins.push(generateMergedStatsAndManifestOptions.options.browserPlugin);
|
|
166
339
|
}
|
|
167
340
|
}
|
|
168
341
|
});
|
|
169
342
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (isStoryBook(config)) {
|
|
343
|
+
var generateMergedStatsAndManifest = function() {
|
|
344
|
+
var _generateMergedStatsAndManifestOptions_options = generateMergedStatsAndManifestOptions.options, nodePlugin = _generateMergedStatsAndManifestOptions_options.nodePlugin, browserPlugin = _generateMergedStatsAndManifestOptions_options.browserPlugin, distOutputDir = _generateMergedStatsAndManifestOptions_options.distOutputDir;
|
|
345
|
+
if (!nodePlugin || !browserPlugin || !distOutputDir) {
|
|
174
346
|
return;
|
|
175
347
|
}
|
|
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
|
-
}
|
|
348
|
+
utils.updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
349
|
+
};
|
|
350
|
+
api.onDevCompileDone(function() {
|
|
351
|
+
generateMergedStatsAndManifest();
|
|
208
352
|
});
|
|
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;
|
|
353
|
+
api.onAfterBuild(function() {
|
|
354
|
+
generateMergedStatsAndManifest();
|
|
216
355
|
});
|
|
217
356
|
}
|
|
218
357
|
};
|
|
219
358
|
};
|
|
220
359
|
|
|
221
|
-
Object.defineProperty(exports, "createModuleFederationConfig", {
|
|
222
|
-
enumerable: true,
|
|
223
|
-
get: function () { return enhanced.createModuleFederationConfig; }
|
|
224
|
-
});
|
|
225
360
|
Object.defineProperty(exports, "PLUGIN_NAME", {
|
|
226
361
|
enumerable: true,
|
|
227
362
|
get: function () { return rspack.PLUGIN_NAME; }
|
|
228
363
|
});
|
|
364
|
+
Object.defineProperty(exports, "createModuleFederationConfig", {
|
|
365
|
+
enumerable: true,
|
|
366
|
+
get: function () { return sdk.createModuleFederationConfig; }
|
|
367
|
+
});
|
|
368
|
+
exports.SSR_DIR = utils.SSR_DIR;
|
|
229
369
|
exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
|
|
230
|
-
exports.RSPACK_PLUGIN_MODULE_FEDERATION_NAME = RSPACK_PLUGIN_MODULE_FEDERATION_NAME;
|
|
231
370
|
exports.isMFFormat = isMFFormat;
|
|
232
371
|
exports.pluginModuleFederation = pluginModuleFederation;
|