@module-federation/rsbuild-plugin 0.0.0-next-20241224163615 → 0.0.0-next-20241225063631
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/index.cjs.js +277 -131
- package/dist/index.esm.js +279 -127
- package/dist/src/cli/index.d.ts +2 -6
- package/dist/src/utils/index.d.ts +0 -1
- package/package.json +5 -21
- package/dist/src/utils/autoDeleteSplitChunkCacheGroups.d.ts +0 -3
- package/dist/utils.cjs.d.ts +0 -1
- package/dist/utils.cjs.js +0 -80
- package/dist/utils.esm.d.ts +0 -1
- package/dist/utils.esm.js +0 -76
package/dist/index.cjs.js
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
var enhanced = require('@module-federation/enhanced');
|
|
4
4
|
var rspack = require('@module-federation/enhanced/rspack');
|
|
5
5
|
var sdk = require('@module-federation/sdk');
|
|
6
|
-
var
|
|
7
|
-
|
|
6
|
+
var util = require('util');
|
|
7
|
+
|
|
8
|
+
function isRegExp(target) {
|
|
9
|
+
return util.types.isRegExp(target);
|
|
10
|
+
}
|
|
8
11
|
|
|
9
12
|
var name = "@module-federation/rsbuild-plugin";
|
|
10
13
|
var version = "0.8.5";
|
|
@@ -21,14 +24,9 @@ var repository = {
|
|
|
21
24
|
var license = "MIT";
|
|
22
25
|
var exports$1 = {
|
|
23
26
|
".": {
|
|
24
|
-
types: "./dist/index.cjs.d.ts",
|
|
25
27
|
"import": "./dist/index.esm.js",
|
|
26
|
-
require: "./dist/index.cjs.js"
|
|
27
|
-
|
|
28
|
-
"./utils": {
|
|
29
|
-
types: "./dist/utils.cjs.d.ts",
|
|
30
|
-
"import": "./dist/utils.esm.js",
|
|
31
|
-
require: "./dist/utils.cjs.js"
|
|
28
|
+
require: "./dist/index.cjs.js",
|
|
29
|
+
types: "./dist/index.cjs.d.ts"
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
32
|
var main = "./dist/index.cjs.js";
|
|
@@ -37,9 +35,6 @@ var typesVersions = {
|
|
|
37
35
|
"*": {
|
|
38
36
|
".": [
|
|
39
37
|
"./dist/index.cjs.d.ts"
|
|
40
|
-
],
|
|
41
|
-
utils: [
|
|
42
|
-
"./dist/utils.cjs.d.ts"
|
|
43
38
|
]
|
|
44
39
|
}
|
|
45
40
|
};
|
|
@@ -56,14 +51,6 @@ var peerDependencies = {
|
|
|
56
51
|
"@module-federation/enhanced": "workspace:*",
|
|
57
52
|
"@rsbuild/core": "1.x"
|
|
58
53
|
};
|
|
59
|
-
var peerDependenciesMeta = {
|
|
60
|
-
"@rsbuild/core": {
|
|
61
|
-
optional: true
|
|
62
|
-
},
|
|
63
|
-
"@module-federation/enhanced": {
|
|
64
|
-
optional: true
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
54
|
var engines = {
|
|
68
55
|
node: ">=16.0.0"
|
|
69
56
|
};
|
|
@@ -88,7 +75,6 @@ var pkgJson = {
|
|
|
88
75
|
dependencies: dependencies,
|
|
89
76
|
devDependencies: devDependencies,
|
|
90
77
|
peerDependencies: peerDependencies,
|
|
91
|
-
peerDependenciesMeta: peerDependenciesMeta,
|
|
92
78
|
engines: engines,
|
|
93
79
|
publishConfig: publishConfig
|
|
94
80
|
};
|
|
@@ -103,19 +89,91 @@ function _array_like_to_array(arr, len) {
|
|
|
103
89
|
function _array_without_holes(arr) {
|
|
104
90
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
105
91
|
}
|
|
92
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
93
|
+
try {
|
|
94
|
+
var info = gen[key](arg);
|
|
95
|
+
var value = info.value;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
reject(error);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (info.done) {
|
|
101
|
+
resolve(value);
|
|
102
|
+
} else {
|
|
103
|
+
Promise.resolve(value).then(_next, _throw);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function _async_to_generator(fn) {
|
|
107
|
+
return function() {
|
|
108
|
+
var self = this, args = arguments;
|
|
109
|
+
return new Promise(function(resolve, reject) {
|
|
110
|
+
var gen = fn.apply(self, args);
|
|
111
|
+
function _next(value) {
|
|
112
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
113
|
+
}
|
|
114
|
+
function _throw(err) {
|
|
115
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
116
|
+
}
|
|
117
|
+
_next(undefined);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function _define_property(obj, key, value) {
|
|
122
|
+
if (key in obj) {
|
|
123
|
+
Object.defineProperty(obj, key, {
|
|
124
|
+
value: value,
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
obj[key] = value;
|
|
131
|
+
}
|
|
132
|
+
return obj;
|
|
133
|
+
}
|
|
106
134
|
function _iterable_to_array(iter) {
|
|
107
135
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
108
136
|
}
|
|
109
137
|
function _non_iterable_spread() {
|
|
110
138
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
111
139
|
}
|
|
140
|
+
function _object_spread(target) {
|
|
141
|
+
for(var i = 1; i < arguments.length; i++){
|
|
142
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
143
|
+
var ownKeys = Object.keys(source);
|
|
144
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
145
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
146
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
ownKeys.forEach(function(key) {
|
|
150
|
+
_define_property(target, key, source[key]);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return target;
|
|
154
|
+
}
|
|
155
|
+
function ownKeys(object, enumerableOnly) {
|
|
156
|
+
var keys = Object.keys(object);
|
|
157
|
+
if (Object.getOwnPropertySymbols) {
|
|
158
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
159
|
+
keys.push.apply(keys, symbols);
|
|
160
|
+
}
|
|
161
|
+
return keys;
|
|
162
|
+
}
|
|
163
|
+
function _object_spread_props(target, source) {
|
|
164
|
+
source = source != null ? source : {};
|
|
165
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
166
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
167
|
+
} else {
|
|
168
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
169
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return target;
|
|
173
|
+
}
|
|
112
174
|
function _to_consumable_array(arr) {
|
|
113
175
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
114
176
|
}
|
|
115
|
-
function _type_of(obj) {
|
|
116
|
-
"@swc/helpers - typeof";
|
|
117
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
118
|
-
}
|
|
119
177
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
120
178
|
if (!o) return;
|
|
121
179
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -124,21 +182,105 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
124
182
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
125
183
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
126
184
|
}
|
|
127
|
-
|
|
128
|
-
var
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
185
|
+
function _ts_generator(thisArg, body) {
|
|
186
|
+
var f, y, t, g, _ = {
|
|
187
|
+
label: 0,
|
|
188
|
+
sent: function() {
|
|
189
|
+
if (t[0] & 1) throw t[1];
|
|
190
|
+
return t[1];
|
|
191
|
+
},
|
|
192
|
+
trys: [],
|
|
193
|
+
ops: []
|
|
194
|
+
};
|
|
195
|
+
return g = {
|
|
196
|
+
next: verb(0),
|
|
197
|
+
"throw": verb(1),
|
|
198
|
+
"return": verb(2)
|
|
199
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
200
|
+
return this;
|
|
201
|
+
}), g;
|
|
202
|
+
function verb(n) {
|
|
203
|
+
return function(v) {
|
|
204
|
+
return step([
|
|
205
|
+
n,
|
|
206
|
+
v
|
|
207
|
+
]);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function step(op) {
|
|
211
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
212
|
+
while(_)try {
|
|
213
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
214
|
+
if (y = 0, t) op = [
|
|
215
|
+
op[0] & 2,
|
|
216
|
+
t.value
|
|
217
|
+
];
|
|
218
|
+
switch(op[0]){
|
|
219
|
+
case 0:
|
|
220
|
+
case 1:
|
|
221
|
+
t = op;
|
|
222
|
+
break;
|
|
223
|
+
case 4:
|
|
224
|
+
_.label++;
|
|
225
|
+
return {
|
|
226
|
+
value: op[1],
|
|
227
|
+
done: false
|
|
228
|
+
};
|
|
229
|
+
case 5:
|
|
230
|
+
_.label++;
|
|
231
|
+
y = op[1];
|
|
232
|
+
op = [
|
|
233
|
+
0
|
|
234
|
+
];
|
|
235
|
+
continue;
|
|
236
|
+
case 7:
|
|
237
|
+
op = _.ops.pop();
|
|
238
|
+
_.trys.pop();
|
|
239
|
+
continue;
|
|
240
|
+
default:
|
|
241
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
242
|
+
_ = 0;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
246
|
+
_.label = op[1];
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
250
|
+
_.label = t[1];
|
|
251
|
+
t = op;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (t && _.label < t[2]) {
|
|
255
|
+
_.label = t[2];
|
|
256
|
+
_.ops.push(op);
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
if (t[2]) _.ops.pop();
|
|
260
|
+
_.trys.pop();
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
op = body.call(thisArg, _);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
op = [
|
|
266
|
+
6,
|
|
267
|
+
e
|
|
268
|
+
];
|
|
269
|
+
y = 0;
|
|
270
|
+
} finally{
|
|
271
|
+
f = t = 0;
|
|
272
|
+
}
|
|
273
|
+
if (op[0] & 5) throw op[1];
|
|
274
|
+
return {
|
|
275
|
+
value: op[0] ? op[1] : void 0,
|
|
276
|
+
done: true
|
|
277
|
+
};
|
|
278
|
+
}
|
|
138
279
|
}
|
|
280
|
+
var PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
139
281
|
var pluginModuleFederation = function(moduleFederationOptions) {
|
|
140
282
|
return {
|
|
141
|
-
name:
|
|
283
|
+
name: PLUGIN_MODULE_FEDERATION_NAME,
|
|
142
284
|
setup: function(api) {
|
|
143
285
|
var sharedOptions = enhanced.parseOptions(moduleFederationOptions.shared || [], function(item, key) {
|
|
144
286
|
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
@@ -156,91 +298,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
156
298
|
var shared = sharedOptions.map(function(shared) {
|
|
157
299
|
return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
|
|
158
300
|
});
|
|
159
|
-
api.onBeforeCreateCompiler(function(param) {
|
|
160
|
-
var bundlerConfigs = param.bundlerConfigs;
|
|
161
|
-
if (!bundlerConfigs) {
|
|
162
|
-
throw new Error('Can not get bundlerConfigs!');
|
|
163
|
-
}
|
|
164
|
-
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
165
|
-
if (!isMFFormat(bundlerConfig)) {
|
|
166
|
-
return;
|
|
167
|
-
} else {
|
|
168
|
-
var _bundlerConfig_output, _bundlerConfig_output1;
|
|
169
|
-
// mf
|
|
170
|
-
utils.autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig);
|
|
171
|
-
var externals = bundlerConfig.externals;
|
|
172
|
-
if (Array.isArray(externals)) {
|
|
173
|
-
var sharedModules = new Set();
|
|
174
|
-
bundlerConfig.externals = externals.filter(function(ext) {
|
|
175
|
-
var sharedModule;
|
|
176
|
-
if (utils.isRegExp(ext)) {
|
|
177
|
-
var match = shared.some(function(dep) {
|
|
178
|
-
if (ext.test(dep) || ext.test(pkgJson.name)) {
|
|
179
|
-
sharedModule = dep;
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
return false;
|
|
183
|
-
});
|
|
184
|
-
match && sharedModule && sharedModules.add(sharedModule);
|
|
185
|
-
return !match;
|
|
186
|
-
}
|
|
187
|
-
if (typeof ext === 'string') {
|
|
188
|
-
if (ext === pkgJson.name) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
var match1 = shared.some(function(dep) {
|
|
192
|
-
if (dep === ext) {
|
|
193
|
-
sharedModule = dep;
|
|
194
|
-
}
|
|
195
|
-
return dep === ext;
|
|
196
|
-
});
|
|
197
|
-
if (match1) {
|
|
198
|
-
sharedModule && sharedModules.add(sharedModule);
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
});
|
|
205
|
-
if (sharedModules.size > 0) {
|
|
206
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
207
|
-
try {
|
|
208
|
-
for(var _iterator = sharedModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
209
|
-
var sharedModule = _step.value;
|
|
210
|
-
logger.log("".concat(sharedModule, " is removed from externals because it is a shared module."));
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_didIteratorError = true;
|
|
214
|
-
_iteratorError = err;
|
|
215
|
-
} finally{
|
|
216
|
-
try {
|
|
217
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
218
|
-
_iterator.return();
|
|
219
|
-
}
|
|
220
|
-
} finally{
|
|
221
|
-
if (_didIteratorError) {
|
|
222
|
-
throw _iteratorError;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal)) {
|
|
229
|
-
bundlerConfig.output.chunkLoadingGlobal = 'jsonp';
|
|
230
|
-
}
|
|
231
|
-
// `uniqueName` is required for react refresh to work
|
|
232
|
-
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
233
|
-
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
234
|
-
}
|
|
235
|
-
if (!bundlerConfig.plugins.find(function(p) {
|
|
236
|
-
return p && p.name === rspack.PLUGIN_NAME;
|
|
237
|
-
})) {
|
|
238
|
-
bundlerConfig.plugins.push(new rspack.ModuleFederationPlugin(moduleFederationOptions));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
// dev config only works on format: 'mf'
|
|
244
301
|
api.modifyRsbuildConfig(function(config) {
|
|
245
302
|
// Change some default configs for remote modules
|
|
246
303
|
if (moduleFederationOptions.exposes) {
|
|
@@ -263,24 +320,113 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
263
320
|
}
|
|
264
321
|
});
|
|
265
322
|
api.modifyEnvironmentConfig(function(config, param) {
|
|
266
|
-
param.mergeEnvironmentConfig;
|
|
323
|
+
var mergeEnvironmentConfig = param.mergeEnvironmentConfig;
|
|
324
|
+
var _config_performance_chunkSplit, _config_performance;
|
|
325
|
+
/**
|
|
326
|
+
* Currently, splitChunks will take precedence over module federation shared modules.
|
|
327
|
+
* So we need to disable the default split chunks rules to make shared modules to work properly.
|
|
328
|
+
* @see https://github.com/module-federation/module-federation-examples/issues/3161
|
|
329
|
+
*/ if (((_config_performance = config.performance) === null || _config_performance === void 0 ? void 0 : (_config_performance_chunkSplit = _config_performance.chunkSplit) === null || _config_performance_chunkSplit === void 0 ? void 0 : _config_performance_chunkSplit.strategy) === 'split-by-experience') {
|
|
330
|
+
config.performance.chunkSplit = _object_spread_props(_object_spread({}, config.performance.chunkSplit), {
|
|
331
|
+
strategy: 'custom'
|
|
332
|
+
});
|
|
333
|
+
}
|
|
267
334
|
// Module Federation runtime uses ES6+ syntax,
|
|
268
335
|
// adding to include and let SWC transform it
|
|
269
336
|
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
270
337
|
/@module-federation[\\/]sdk/,
|
|
271
338
|
/@module-federation[\\/]runtime/
|
|
272
339
|
]);
|
|
273
|
-
|
|
340
|
+
// filter external with shared config,
|
|
341
|
+
var externals = config.output.externals;
|
|
342
|
+
if (Array.isArray(externals)) {
|
|
343
|
+
var sharedModules = new Set();
|
|
344
|
+
config.output.externals = externals.filter(function(ext) {
|
|
345
|
+
var sharedModule;
|
|
346
|
+
if (isRegExp(ext)) {
|
|
347
|
+
var match = shared.some(function(dep) {
|
|
348
|
+
if (ext.test(dep) || ext.test(pkgJson.name)) {
|
|
349
|
+
sharedModule = dep;
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
return false;
|
|
353
|
+
});
|
|
354
|
+
match && sharedModule && sharedModules.add(sharedModule);
|
|
355
|
+
return !match;
|
|
356
|
+
}
|
|
357
|
+
if (typeof ext === 'string') {
|
|
358
|
+
if (ext === pkgJson.name) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
var match1 = shared.some(function(dep) {
|
|
362
|
+
if (dep === ext) {
|
|
363
|
+
sharedModule = dep;
|
|
364
|
+
}
|
|
365
|
+
return dep === ext;
|
|
366
|
+
});
|
|
367
|
+
if (match1) {
|
|
368
|
+
sharedModule && sharedModules.add(sharedModule);
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
return true;
|
|
374
|
+
});
|
|
375
|
+
if (sharedModules.size > 0) {
|
|
376
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
377
|
+
try {
|
|
378
|
+
for(var _iterator = sharedModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
379
|
+
var sharedModule = _step.value;
|
|
380
|
+
logger.log("".concat(sharedModule, " is removed from externals because it is a shared module."));
|
|
381
|
+
}
|
|
382
|
+
} catch (err) {
|
|
383
|
+
_didIteratorError = true;
|
|
384
|
+
_iteratorError = err;
|
|
385
|
+
} finally{
|
|
386
|
+
try {
|
|
387
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
388
|
+
_iterator.return();
|
|
389
|
+
}
|
|
390
|
+
} finally{
|
|
391
|
+
if (_didIteratorError) {
|
|
392
|
+
throw _iteratorError;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
var mfConfig = {
|
|
399
|
+
tools: {
|
|
400
|
+
rspack: {
|
|
401
|
+
output: {
|
|
402
|
+
chunkLoading: 'jsonp'
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
return mergeEnvironmentConfig(config, mfConfig);
|
|
274
408
|
});
|
|
409
|
+
api.modifyBundlerChain(/*#__PURE__*/ function() {
|
|
410
|
+
var _ref = _async_to_generator(function(chain) {
|
|
411
|
+
return _ts_generator(this, function(_state) {
|
|
412
|
+
chain.plugin('module-federation').use(rspack.ModuleFederationPlugin, [
|
|
413
|
+
moduleFederationOptions
|
|
414
|
+
]);
|
|
415
|
+
// `uniqueName` is required for react refresh to work
|
|
416
|
+
if (!chain.output.get('uniqueName')) {
|
|
417
|
+
chain.output.set('uniqueName', moduleFederationOptions.name);
|
|
418
|
+
}
|
|
419
|
+
return [
|
|
420
|
+
2
|
|
421
|
+
];
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
return function(chain) {
|
|
425
|
+
return _ref.apply(this, arguments);
|
|
426
|
+
};
|
|
427
|
+
}());
|
|
275
428
|
}
|
|
276
429
|
};
|
|
277
430
|
};
|
|
278
431
|
|
|
279
|
-
Object.defineProperty(exports, "PLUGIN_NAME", {
|
|
280
|
-
enumerable: true,
|
|
281
|
-
get: function () { return rspack.PLUGIN_NAME; }
|
|
282
|
-
});
|
|
283
|
-
exports.RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = RSBUILD_PLUGIN_MODULE_FEDERATION_NAME;
|
|
284
|
-
exports.RSPACK_PLUGIN_MODULE_FEDERATION_NAME = RSPACK_PLUGIN_MODULE_FEDERATION_NAME;
|
|
285
|
-
exports.isMFFormat = isMFFormat;
|
|
286
432
|
exports.pluginModuleFederation = pluginModuleFederation;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { parseOptions } from '@module-federation/enhanced';
|
|
2
|
-
import {
|
|
3
|
-
export { PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
2
|
+
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
3
|
import { createLogger, isRequiredVersion } from '@module-federation/sdk';
|
|
5
|
-
import
|
|
6
|
-
|
|
4
|
+
import util from 'util';
|
|
5
|
+
|
|
6
|
+
function isRegExp(target) {
|
|
7
|
+
return util.types.isRegExp(target);
|
|
8
|
+
}
|
|
7
9
|
|
|
8
10
|
var name = "@module-federation/rsbuild-plugin";
|
|
9
11
|
var version = "0.8.5";
|
|
@@ -20,14 +22,9 @@ var repository = {
|
|
|
20
22
|
var license = "MIT";
|
|
21
23
|
var exports = {
|
|
22
24
|
".": {
|
|
23
|
-
types: "./dist/index.cjs.d.ts",
|
|
24
25
|
"import": "./dist/index.esm.js",
|
|
25
|
-
require: "./dist/index.cjs.js"
|
|
26
|
-
|
|
27
|
-
"./utils": {
|
|
28
|
-
types: "./dist/utils.cjs.d.ts",
|
|
29
|
-
"import": "./dist/utils.esm.js",
|
|
30
|
-
require: "./dist/utils.cjs.js"
|
|
26
|
+
require: "./dist/index.cjs.js",
|
|
27
|
+
types: "./dist/index.cjs.d.ts"
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
30
|
var main = "./dist/index.cjs.js";
|
|
@@ -36,9 +33,6 @@ var typesVersions = {
|
|
|
36
33
|
"*": {
|
|
37
34
|
".": [
|
|
38
35
|
"./dist/index.cjs.d.ts"
|
|
39
|
-
],
|
|
40
|
-
utils: [
|
|
41
|
-
"./dist/utils.cjs.d.ts"
|
|
42
36
|
]
|
|
43
37
|
}
|
|
44
38
|
};
|
|
@@ -55,14 +49,6 @@ var peerDependencies = {
|
|
|
55
49
|
"@module-federation/enhanced": "workspace:*",
|
|
56
50
|
"@rsbuild/core": "1.x"
|
|
57
51
|
};
|
|
58
|
-
var peerDependenciesMeta = {
|
|
59
|
-
"@rsbuild/core": {
|
|
60
|
-
optional: true
|
|
61
|
-
},
|
|
62
|
-
"@module-federation/enhanced": {
|
|
63
|
-
optional: true
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
52
|
var engines = {
|
|
67
53
|
node: ">=16.0.0"
|
|
68
54
|
};
|
|
@@ -87,7 +73,6 @@ var pkgJson = {
|
|
|
87
73
|
dependencies: dependencies,
|
|
88
74
|
devDependencies: devDependencies,
|
|
89
75
|
peerDependencies: peerDependencies,
|
|
90
|
-
peerDependenciesMeta: peerDependenciesMeta,
|
|
91
76
|
engines: engines,
|
|
92
77
|
publishConfig: publishConfig
|
|
93
78
|
};
|
|
@@ -102,19 +87,91 @@ function _array_like_to_array(arr, len) {
|
|
|
102
87
|
function _array_without_holes(arr) {
|
|
103
88
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
104
89
|
}
|
|
90
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
91
|
+
try {
|
|
92
|
+
var info = gen[key](arg);
|
|
93
|
+
var value = info.value;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
reject(error);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (info.done) {
|
|
99
|
+
resolve(value);
|
|
100
|
+
} else {
|
|
101
|
+
Promise.resolve(value).then(_next, _throw);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function _async_to_generator(fn) {
|
|
105
|
+
return function() {
|
|
106
|
+
var self = this, args = arguments;
|
|
107
|
+
return new Promise(function(resolve, reject) {
|
|
108
|
+
var gen = fn.apply(self, args);
|
|
109
|
+
function _next(value) {
|
|
110
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
111
|
+
}
|
|
112
|
+
function _throw(err) {
|
|
113
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
114
|
+
}
|
|
115
|
+
_next(undefined);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function _define_property(obj, key, value) {
|
|
120
|
+
if (key in obj) {
|
|
121
|
+
Object.defineProperty(obj, key, {
|
|
122
|
+
value: value,
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
obj[key] = value;
|
|
129
|
+
}
|
|
130
|
+
return obj;
|
|
131
|
+
}
|
|
105
132
|
function _iterable_to_array(iter) {
|
|
106
133
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
107
134
|
}
|
|
108
135
|
function _non_iterable_spread() {
|
|
109
136
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
137
|
}
|
|
138
|
+
function _object_spread(target) {
|
|
139
|
+
for(var i = 1; i < arguments.length; i++){
|
|
140
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
141
|
+
var ownKeys = Object.keys(source);
|
|
142
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
143
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
144
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
ownKeys.forEach(function(key) {
|
|
148
|
+
_define_property(target, key, source[key]);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return target;
|
|
152
|
+
}
|
|
153
|
+
function ownKeys(object, enumerableOnly) {
|
|
154
|
+
var keys = Object.keys(object);
|
|
155
|
+
if (Object.getOwnPropertySymbols) {
|
|
156
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
157
|
+
keys.push.apply(keys, symbols);
|
|
158
|
+
}
|
|
159
|
+
return keys;
|
|
160
|
+
}
|
|
161
|
+
function _object_spread_props(target, source) {
|
|
162
|
+
source = source != null ? source : {};
|
|
163
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
164
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
165
|
+
} else {
|
|
166
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
167
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return target;
|
|
171
|
+
}
|
|
111
172
|
function _to_consumable_array(arr) {
|
|
112
173
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
113
174
|
}
|
|
114
|
-
function _type_of(obj) {
|
|
115
|
-
"@swc/helpers - typeof";
|
|
116
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
117
|
-
}
|
|
118
175
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
119
176
|
if (!o) return;
|
|
120
177
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -123,21 +180,105 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
123
180
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
124
181
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
125
182
|
}
|
|
126
|
-
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return
|
|
183
|
+
function _ts_generator(thisArg, body) {
|
|
184
|
+
var f, y, t, g, _ = {
|
|
185
|
+
label: 0,
|
|
186
|
+
sent: function() {
|
|
187
|
+
if (t[0] & 1) throw t[1];
|
|
188
|
+
return t[1];
|
|
189
|
+
},
|
|
190
|
+
trys: [],
|
|
191
|
+
ops: []
|
|
192
|
+
};
|
|
193
|
+
return g = {
|
|
194
|
+
next: verb(0),
|
|
195
|
+
"throw": verb(1),
|
|
196
|
+
"return": verb(2)
|
|
197
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
198
|
+
return this;
|
|
199
|
+
}), g;
|
|
200
|
+
function verb(n) {
|
|
201
|
+
return function(v) {
|
|
202
|
+
return step([
|
|
203
|
+
n,
|
|
204
|
+
v
|
|
205
|
+
]);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function step(op) {
|
|
209
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
210
|
+
while(_)try {
|
|
211
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
212
|
+
if (y = 0, t) op = [
|
|
213
|
+
op[0] & 2,
|
|
214
|
+
t.value
|
|
215
|
+
];
|
|
216
|
+
switch(op[0]){
|
|
217
|
+
case 0:
|
|
218
|
+
case 1:
|
|
219
|
+
t = op;
|
|
220
|
+
break;
|
|
221
|
+
case 4:
|
|
222
|
+
_.label++;
|
|
223
|
+
return {
|
|
224
|
+
value: op[1],
|
|
225
|
+
done: false
|
|
226
|
+
};
|
|
227
|
+
case 5:
|
|
228
|
+
_.label++;
|
|
229
|
+
y = op[1];
|
|
230
|
+
op = [
|
|
231
|
+
0
|
|
232
|
+
];
|
|
233
|
+
continue;
|
|
234
|
+
case 7:
|
|
235
|
+
op = _.ops.pop();
|
|
236
|
+
_.trys.pop();
|
|
237
|
+
continue;
|
|
238
|
+
default:
|
|
239
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
240
|
+
_ = 0;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
244
|
+
_.label = op[1];
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
248
|
+
_.label = t[1];
|
|
249
|
+
t = op;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
if (t && _.label < t[2]) {
|
|
253
|
+
_.label = t[2];
|
|
254
|
+
_.ops.push(op);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
if (t[2]) _.ops.pop();
|
|
258
|
+
_.trys.pop();
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
op = body.call(thisArg, _);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
op = [
|
|
264
|
+
6,
|
|
265
|
+
e
|
|
266
|
+
];
|
|
267
|
+
y = 0;
|
|
268
|
+
} finally{
|
|
269
|
+
f = t = 0;
|
|
270
|
+
}
|
|
271
|
+
if (op[0] & 5) throw op[1];
|
|
272
|
+
return {
|
|
273
|
+
value: op[0] ? op[1] : void 0,
|
|
274
|
+
done: true
|
|
275
|
+
};
|
|
276
|
+
}
|
|
137
277
|
}
|
|
278
|
+
var PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
138
279
|
var pluginModuleFederation = function(moduleFederationOptions) {
|
|
139
280
|
return {
|
|
140
|
-
name:
|
|
281
|
+
name: PLUGIN_MODULE_FEDERATION_NAME,
|
|
141
282
|
setup: function(api) {
|
|
142
283
|
var sharedOptions = parseOptions(moduleFederationOptions.shared || [], function(item, key) {
|
|
143
284
|
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
@@ -155,91 +296,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
155
296
|
var shared = sharedOptions.map(function(shared) {
|
|
156
297
|
return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
|
|
157
298
|
});
|
|
158
|
-
api.onBeforeCreateCompiler(function(param) {
|
|
159
|
-
var bundlerConfigs = param.bundlerConfigs;
|
|
160
|
-
if (!bundlerConfigs) {
|
|
161
|
-
throw new Error('Can not get bundlerConfigs!');
|
|
162
|
-
}
|
|
163
|
-
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
164
|
-
if (!isMFFormat(bundlerConfig)) {
|
|
165
|
-
return;
|
|
166
|
-
} else {
|
|
167
|
-
var _bundlerConfig_output, _bundlerConfig_output1;
|
|
168
|
-
// mf
|
|
169
|
-
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig);
|
|
170
|
-
var externals = bundlerConfig.externals;
|
|
171
|
-
if (Array.isArray(externals)) {
|
|
172
|
-
var sharedModules = new Set();
|
|
173
|
-
bundlerConfig.externals = externals.filter(function(ext) {
|
|
174
|
-
var sharedModule;
|
|
175
|
-
if (isRegExp(ext)) {
|
|
176
|
-
var match = shared.some(function(dep) {
|
|
177
|
-
if (ext.test(dep) || ext.test(pkgJson.name)) {
|
|
178
|
-
sharedModule = dep;
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
return false;
|
|
182
|
-
});
|
|
183
|
-
match && sharedModule && sharedModules.add(sharedModule);
|
|
184
|
-
return !match;
|
|
185
|
-
}
|
|
186
|
-
if (typeof ext === 'string') {
|
|
187
|
-
if (ext === pkgJson.name) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
var match1 = shared.some(function(dep) {
|
|
191
|
-
if (dep === ext) {
|
|
192
|
-
sharedModule = dep;
|
|
193
|
-
}
|
|
194
|
-
return dep === ext;
|
|
195
|
-
});
|
|
196
|
-
if (match1) {
|
|
197
|
-
sharedModule && sharedModules.add(sharedModule);
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
return true;
|
|
203
|
-
});
|
|
204
|
-
if (sharedModules.size > 0) {
|
|
205
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
206
|
-
try {
|
|
207
|
-
for(var _iterator = sharedModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
208
|
-
var sharedModule = _step.value;
|
|
209
|
-
logger.log("".concat(sharedModule, " is removed from externals because it is a shared module."));
|
|
210
|
-
}
|
|
211
|
-
} catch (err) {
|
|
212
|
-
_didIteratorError = true;
|
|
213
|
-
_iteratorError = err;
|
|
214
|
-
} finally{
|
|
215
|
-
try {
|
|
216
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
217
|
-
_iterator.return();
|
|
218
|
-
}
|
|
219
|
-
} finally{
|
|
220
|
-
if (_didIteratorError) {
|
|
221
|
-
throw _iteratorError;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (!((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.chunkLoadingGlobal)) {
|
|
228
|
-
bundlerConfig.output.chunkLoadingGlobal = 'jsonp';
|
|
229
|
-
}
|
|
230
|
-
// `uniqueName` is required for react refresh to work
|
|
231
|
-
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.uniqueName)) {
|
|
232
|
-
bundlerConfig.output.uniqueName = moduleFederationOptions.name;
|
|
233
|
-
}
|
|
234
|
-
if (!bundlerConfig.plugins.find(function(p) {
|
|
235
|
-
return p && p.name === PLUGIN_NAME;
|
|
236
|
-
})) {
|
|
237
|
-
bundlerConfig.plugins.push(new ModuleFederationPlugin(moduleFederationOptions));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
// dev config only works on format: 'mf'
|
|
243
299
|
api.modifyRsbuildConfig(function(config) {
|
|
244
300
|
// Change some default configs for remote modules
|
|
245
301
|
if (moduleFederationOptions.exposes) {
|
|
@@ -262,17 +318,113 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
262
318
|
}
|
|
263
319
|
});
|
|
264
320
|
api.modifyEnvironmentConfig(function(config, param) {
|
|
265
|
-
param.mergeEnvironmentConfig;
|
|
321
|
+
var mergeEnvironmentConfig = param.mergeEnvironmentConfig;
|
|
322
|
+
var _config_performance_chunkSplit, _config_performance;
|
|
323
|
+
/**
|
|
324
|
+
* Currently, splitChunks will take precedence over module federation shared modules.
|
|
325
|
+
* So we need to disable the default split chunks rules to make shared modules to work properly.
|
|
326
|
+
* @see https://github.com/module-federation/module-federation-examples/issues/3161
|
|
327
|
+
*/ if (((_config_performance = config.performance) === null || _config_performance === void 0 ? void 0 : (_config_performance_chunkSplit = _config_performance.chunkSplit) === null || _config_performance_chunkSplit === void 0 ? void 0 : _config_performance_chunkSplit.strategy) === 'split-by-experience') {
|
|
328
|
+
config.performance.chunkSplit = _object_spread_props(_object_spread({}, config.performance.chunkSplit), {
|
|
329
|
+
strategy: 'custom'
|
|
330
|
+
});
|
|
331
|
+
}
|
|
266
332
|
// Module Federation runtime uses ES6+ syntax,
|
|
267
333
|
// adding to include and let SWC transform it
|
|
268
334
|
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
269
335
|
/@module-federation[\\/]sdk/,
|
|
270
336
|
/@module-federation[\\/]runtime/
|
|
271
337
|
]);
|
|
272
|
-
|
|
338
|
+
// filter external with shared config,
|
|
339
|
+
var externals = config.output.externals;
|
|
340
|
+
if (Array.isArray(externals)) {
|
|
341
|
+
var sharedModules = new Set();
|
|
342
|
+
config.output.externals = externals.filter(function(ext) {
|
|
343
|
+
var sharedModule;
|
|
344
|
+
if (isRegExp(ext)) {
|
|
345
|
+
var match = shared.some(function(dep) {
|
|
346
|
+
if (ext.test(dep) || ext.test(pkgJson.name)) {
|
|
347
|
+
sharedModule = dep;
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
});
|
|
352
|
+
match && sharedModule && sharedModules.add(sharedModule);
|
|
353
|
+
return !match;
|
|
354
|
+
}
|
|
355
|
+
if (typeof ext === 'string') {
|
|
356
|
+
if (ext === pkgJson.name) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
var match1 = shared.some(function(dep) {
|
|
360
|
+
if (dep === ext) {
|
|
361
|
+
sharedModule = dep;
|
|
362
|
+
}
|
|
363
|
+
return dep === ext;
|
|
364
|
+
});
|
|
365
|
+
if (match1) {
|
|
366
|
+
sharedModule && sharedModules.add(sharedModule);
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
});
|
|
373
|
+
if (sharedModules.size > 0) {
|
|
374
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
375
|
+
try {
|
|
376
|
+
for(var _iterator = sharedModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
377
|
+
var sharedModule = _step.value;
|
|
378
|
+
logger.log("".concat(sharedModule, " is removed from externals because it is a shared module."));
|
|
379
|
+
}
|
|
380
|
+
} catch (err) {
|
|
381
|
+
_didIteratorError = true;
|
|
382
|
+
_iteratorError = err;
|
|
383
|
+
} finally{
|
|
384
|
+
try {
|
|
385
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
386
|
+
_iterator.return();
|
|
387
|
+
}
|
|
388
|
+
} finally{
|
|
389
|
+
if (_didIteratorError) {
|
|
390
|
+
throw _iteratorError;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
var mfConfig = {
|
|
397
|
+
tools: {
|
|
398
|
+
rspack: {
|
|
399
|
+
output: {
|
|
400
|
+
chunkLoading: 'jsonp'
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
return mergeEnvironmentConfig(config, mfConfig);
|
|
273
406
|
});
|
|
407
|
+
api.modifyBundlerChain(/*#__PURE__*/ function() {
|
|
408
|
+
var _ref = _async_to_generator(function(chain) {
|
|
409
|
+
return _ts_generator(this, function(_state) {
|
|
410
|
+
chain.plugin('module-federation').use(ModuleFederationPlugin, [
|
|
411
|
+
moduleFederationOptions
|
|
412
|
+
]);
|
|
413
|
+
// `uniqueName` is required for react refresh to work
|
|
414
|
+
if (!chain.output.get('uniqueName')) {
|
|
415
|
+
chain.output.set('uniqueName', moduleFederationOptions.name);
|
|
416
|
+
}
|
|
417
|
+
return [
|
|
418
|
+
2
|
|
419
|
+
];
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
return function(chain) {
|
|
423
|
+
return _ref.apply(this, arguments);
|
|
424
|
+
};
|
|
425
|
+
}());
|
|
274
426
|
}
|
|
275
427
|
};
|
|
276
428
|
};
|
|
277
429
|
|
|
278
|
-
export {
|
|
430
|
+
export { pluginModuleFederation };
|
package/dist/src/cli/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
2
1
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
-
import type { RsbuildPlugin
|
|
2
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
4
3
|
type ModuleFederationOptions = moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
5
|
-
declare const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = "rsbuild:module-federation-enhanced";
|
|
6
|
-
declare const RSPACK_PLUGIN_MODULE_FEDERATION_NAME = "module-federation";
|
|
7
|
-
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, RSPACK_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, };
|
|
8
|
-
export declare function isMFFormat(bundlerConfig: Rspack.Configuration): boolean;
|
|
9
4
|
export declare const pluginModuleFederation: (moduleFederationOptions: ModuleFederationOptions) => RsbuildPlugin;
|
|
5
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/rsbuild-plugin",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20241225063631",
|
|
4
4
|
"description": "Module Federation plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://module-federation.io",
|
|
6
6
|
"bugs": {
|
|
@@ -14,14 +14,9 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./dist/index.cjs.d.ts",
|
|
18
17
|
"import": "./dist/index.esm.js",
|
|
19
|
-
"require": "./dist/index.cjs.js"
|
|
20
|
-
|
|
21
|
-
"./utils": {
|
|
22
|
-
"types": "./dist/utils.cjs.d.ts",
|
|
23
|
-
"import": "./dist/utils.esm.js",
|
|
24
|
-
"require": "./dist/utils.cjs.js"
|
|
18
|
+
"require": "./dist/index.cjs.js",
|
|
19
|
+
"types": "./dist/index.cjs.d.ts"
|
|
25
20
|
}
|
|
26
21
|
},
|
|
27
22
|
"main": "./dist/index.cjs.js",
|
|
@@ -30,9 +25,6 @@
|
|
|
30
25
|
"*": {
|
|
31
26
|
".": [
|
|
32
27
|
"./dist/index.cjs.d.ts"
|
|
33
|
-
],
|
|
34
|
-
"utils": [
|
|
35
|
-
"./dist/utils.cjs.d.ts"
|
|
36
28
|
]
|
|
37
29
|
}
|
|
38
30
|
},
|
|
@@ -40,22 +32,14 @@
|
|
|
40
32
|
"dist"
|
|
41
33
|
],
|
|
42
34
|
"dependencies": {
|
|
43
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
35
|
+
"@module-federation/sdk": "0.0.0-next-20241225063631"
|
|
44
36
|
},
|
|
45
37
|
"devDependencies": {
|
|
46
38
|
"@rsbuild/core": "^1.0.19"
|
|
47
39
|
},
|
|
48
40
|
"peerDependencies": {
|
|
49
41
|
"@rsbuild/core": "1.x",
|
|
50
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
51
|
-
},
|
|
52
|
-
"peerDependenciesMeta": {
|
|
53
|
-
"@rsbuild/core": {
|
|
54
|
-
"optional": true
|
|
55
|
-
},
|
|
56
|
-
"@module-federation/enhanced": {
|
|
57
|
-
"optional": true
|
|
58
|
-
}
|
|
42
|
+
"@module-federation/enhanced": "0.0.0-next-20241225063631"
|
|
59
43
|
},
|
|
60
44
|
"engines": {
|
|
61
45
|
"node": ">=16.0.0"
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
import type { Rspack } from '@rsbuild/core';
|
|
3
|
-
export declare function autoDeleteSplitChunkCacheGroups(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, bundlerConfig: Rspack.Configuration): void;
|
package/dist/utils.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/utils/index";
|
package/dist/utils.cjs.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var util = require('util');
|
|
4
|
-
|
|
5
|
-
var DEFAULT_ASSET_PREFIX = '/';
|
|
6
|
-
|
|
7
|
-
// lib-polyfill.js: include core-js,@babel/runtime,@swc/helpers,tslib.
|
|
8
|
-
// lib-react.js: include react,react-dom.
|
|
9
|
-
// lib-router.js: include react-router,react-router-dom,history,@remix-run/router.
|
|
10
|
-
// lib-lodash.js: include lodash,lodash-es.
|
|
11
|
-
// lib-antd.js: include antd.
|
|
12
|
-
// lib-arco.js: include @arco-design/web-react.
|
|
13
|
-
// lib-semi.js: include @douyinfe/semi-ui.
|
|
14
|
-
// lib-axios.js: include axios.
|
|
15
|
-
var SPLIT_CHUNK_MAP = {
|
|
16
|
-
REACT: 'react',
|
|
17
|
-
ROUTER: 'router',
|
|
18
|
-
LODASH: 'lib-lodash',
|
|
19
|
-
ANTD: 'lib-antd',
|
|
20
|
-
ARCO: 'lib-arco',
|
|
21
|
-
SEMI: 'lib-semi',
|
|
22
|
-
AXIOS: 'lib-axios'
|
|
23
|
-
};
|
|
24
|
-
var SHARED_SPLIT_CHUNK_MAP = {
|
|
25
|
-
react: SPLIT_CHUNK_MAP.REACT,
|
|
26
|
-
'react-dom': SPLIT_CHUNK_MAP.REACT,
|
|
27
|
-
'react-router': SPLIT_CHUNK_MAP.ROUTER,
|
|
28
|
-
'react-router-dom': SPLIT_CHUNK_MAP.ROUTER,
|
|
29
|
-
'@remix-run/router': SPLIT_CHUNK_MAP.ROUTER,
|
|
30
|
-
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
31
|
-
'lodash-es': SPLIT_CHUNK_MAP.LODASH,
|
|
32
|
-
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
33
|
-
'@arco-design/web-react': SPLIT_CHUNK_MAP.ARCO,
|
|
34
|
-
'@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
|
|
35
|
-
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
36
|
-
};
|
|
37
|
-
function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
38
|
-
var _bundlerConfig_optimization;
|
|
39
|
-
if (!mfConfig.shared) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!((_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks) || !bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
var arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
|
|
46
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
47
|
-
try {
|
|
48
|
-
for(var _iterator = arrayShared[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
49
|
-
var shared = _step.value;
|
|
50
|
-
var splitChunkKey = SHARED_SPLIT_CHUNK_MAP[shared];
|
|
51
|
-
if (!splitChunkKey) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey]) {
|
|
55
|
-
delete bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
_didIteratorError = true;
|
|
60
|
-
_iteratorError = err;
|
|
61
|
-
} finally{
|
|
62
|
-
try {
|
|
63
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
64
|
-
_iterator.return();
|
|
65
|
-
}
|
|
66
|
-
} finally{
|
|
67
|
-
if (_didIteratorError) {
|
|
68
|
-
throw _iteratorError;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function isRegExp(target) {
|
|
75
|
-
return util.types.isRegExp(target);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
exports.DEFAULT_ASSET_PREFIX = DEFAULT_ASSET_PREFIX;
|
|
79
|
-
exports.autoDeleteSplitChunkCacheGroups = autoDeleteSplitChunkCacheGroups;
|
|
80
|
-
exports.isRegExp = isRegExp;
|
package/dist/utils.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/utils/index";
|
package/dist/utils.esm.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import util from 'util';
|
|
2
|
-
|
|
3
|
-
var DEFAULT_ASSET_PREFIX = '/';
|
|
4
|
-
|
|
5
|
-
// lib-polyfill.js: include core-js,@babel/runtime,@swc/helpers,tslib.
|
|
6
|
-
// lib-react.js: include react,react-dom.
|
|
7
|
-
// lib-router.js: include react-router,react-router-dom,history,@remix-run/router.
|
|
8
|
-
// lib-lodash.js: include lodash,lodash-es.
|
|
9
|
-
// lib-antd.js: include antd.
|
|
10
|
-
// lib-arco.js: include @arco-design/web-react.
|
|
11
|
-
// lib-semi.js: include @douyinfe/semi-ui.
|
|
12
|
-
// lib-axios.js: include axios.
|
|
13
|
-
var SPLIT_CHUNK_MAP = {
|
|
14
|
-
REACT: 'react',
|
|
15
|
-
ROUTER: 'router',
|
|
16
|
-
LODASH: 'lib-lodash',
|
|
17
|
-
ANTD: 'lib-antd',
|
|
18
|
-
ARCO: 'lib-arco',
|
|
19
|
-
SEMI: 'lib-semi',
|
|
20
|
-
AXIOS: 'lib-axios'
|
|
21
|
-
};
|
|
22
|
-
var SHARED_SPLIT_CHUNK_MAP = {
|
|
23
|
-
react: SPLIT_CHUNK_MAP.REACT,
|
|
24
|
-
'react-dom': SPLIT_CHUNK_MAP.REACT,
|
|
25
|
-
'react-router': SPLIT_CHUNK_MAP.ROUTER,
|
|
26
|
-
'react-router-dom': SPLIT_CHUNK_MAP.ROUTER,
|
|
27
|
-
'@remix-run/router': SPLIT_CHUNK_MAP.ROUTER,
|
|
28
|
-
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
29
|
-
'lodash-es': SPLIT_CHUNK_MAP.LODASH,
|
|
30
|
-
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
31
|
-
'@arco-design/web-react': SPLIT_CHUNK_MAP.ARCO,
|
|
32
|
-
'@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
|
|
33
|
-
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
34
|
-
};
|
|
35
|
-
function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
36
|
-
var _bundlerConfig_optimization;
|
|
37
|
-
if (!mfConfig.shared) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (!((_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks) || !bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
|
|
44
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
45
|
-
try {
|
|
46
|
-
for(var _iterator = arrayShared[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
47
|
-
var shared = _step.value;
|
|
48
|
-
var splitChunkKey = SHARED_SPLIT_CHUNK_MAP[shared];
|
|
49
|
-
if (!splitChunkKey) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey]) {
|
|
53
|
-
delete bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
_didIteratorError = true;
|
|
58
|
-
_iteratorError = err;
|
|
59
|
-
} finally{
|
|
60
|
-
try {
|
|
61
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
62
|
-
_iterator.return();
|
|
63
|
-
}
|
|
64
|
-
} finally{
|
|
65
|
-
if (_didIteratorError) {
|
|
66
|
-
throw _iteratorError;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function isRegExp(target) {
|
|
73
|
-
return util.types.isRegExp(target);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { DEFAULT_ASSET_PREFIX, autoDeleteSplitChunkCacheGroups, isRegExp };
|