@module-federation/rsbuild-plugin 0.9.1 → 0.11.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/index.cjs.js +27 -7
- package/dist/index.esm.js +24 -7
- package/dist/src/cli/index.d.ts +1 -0
- package/dist/src/cli/index.spec.d.ts +1 -0
- package/dist/src/utils/autoDeleteSplitChunkCacheGroups.d.ts +47 -1
- package/dist/utils.cjs.js +5 -5
- package/dist/utils.esm.js +5 -5
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -7,7 +7,7 @@ var utils = require('./utils.cjs.js');
|
|
|
7
7
|
require('util');
|
|
8
8
|
|
|
9
9
|
var name = "@module-federation/rsbuild-plugin";
|
|
10
|
-
var version = "0.
|
|
10
|
+
var version = "0.11.0";
|
|
11
11
|
var description = "Module Federation plugin for Rsbuild";
|
|
12
12
|
var homepage = "https://module-federation.io";
|
|
13
13
|
var bugs = {
|
|
@@ -124,14 +124,22 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
124
124
|
var RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
125
125
|
var RSPACK_PLUGIN_MODULE_FEDERATION_NAME = 'module-federation';
|
|
126
126
|
var LIB_FORMAT = [
|
|
127
|
-
'commonjs',
|
|
128
127
|
'umd',
|
|
129
128
|
'modern-module'
|
|
130
129
|
];
|
|
130
|
+
function isStoryBook(rsbuildConfig) {
|
|
131
|
+
var _rsbuildConfig_plugins;
|
|
132
|
+
if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find(function(p) {
|
|
133
|
+
return p && 'name' in p && p.name === 'module-federation-storybook-plugin';
|
|
134
|
+
})) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
131
138
|
function isMFFormat(bundlerConfig) {
|
|
132
139
|
var _bundlerConfig_output;
|
|
133
140
|
var library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
134
|
-
return !((typeof library === "undefined" ? "undefined" : _type_of(library)) === 'object' && !Array.isArray(library) && 'type' in library &&
|
|
141
|
+
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
|
|
142
|
+
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
135
143
|
}
|
|
136
144
|
var pluginModuleFederation = function(moduleFederationOptions) {
|
|
137
145
|
return {
|
|
@@ -161,10 +169,12 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
161
169
|
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
162
170
|
if (!isMFFormat(bundlerConfig)) {
|
|
163
171
|
return;
|
|
172
|
+
} else if (isStoryBook(api.getRsbuildConfig())) {
|
|
173
|
+
bundlerConfig.output.uniqueName = "".concat(moduleFederationOptions.name, "-storybook-host");
|
|
164
174
|
} else {
|
|
165
|
-
var _bundlerConfig_output, _bundlerConfig_output1;
|
|
175
|
+
var _bundlerConfig_optimization, _bundlerConfig_output, _bundlerConfig_output1;
|
|
166
176
|
// mf
|
|
167
|
-
utils.autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig);
|
|
177
|
+
utils.autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
168
178
|
var externals = bundlerConfig.externals;
|
|
169
179
|
if (Array.isArray(externals)) {
|
|
170
180
|
var sharedModules = new Set();
|
|
@@ -232,6 +242,9 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
232
242
|
if (!bundlerConfig.plugins.find(function(p) {
|
|
233
243
|
return p && p.name === rspack.PLUGIN_NAME;
|
|
234
244
|
})) {
|
|
245
|
+
if (!moduleFederationOptions.shareStrategy) {
|
|
246
|
+
moduleFederationOptions.shareStrategy = 'loaded-first';
|
|
247
|
+
}
|
|
235
248
|
bundlerConfig.plugins.push(new rspack.ModuleFederationPlugin(moduleFederationOptions));
|
|
236
249
|
}
|
|
237
250
|
}
|
|
@@ -239,6 +252,10 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
239
252
|
});
|
|
240
253
|
// dev config only works on format: 'mf'
|
|
241
254
|
api.modifyRsbuildConfig(function(config) {
|
|
255
|
+
// skip storybook
|
|
256
|
+
if (isStoryBook(config)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
242
259
|
// Change some default configs for remote modules
|
|
243
260
|
if (moduleFederationOptions.exposes) {
|
|
244
261
|
var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
@@ -263,8 +280,7 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
263
280
|
// Module Federation runtime uses ES6+ syntax,
|
|
264
281
|
// adding to include and let SWC transform it
|
|
265
282
|
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
266
|
-
/@module-federation[\\/]
|
|
267
|
-
/@module-federation[\\/]runtime/
|
|
283
|
+
/@module-federation[\\/]/
|
|
268
284
|
]);
|
|
269
285
|
return config;
|
|
270
286
|
});
|
|
@@ -272,6 +288,10 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
272
288
|
};
|
|
273
289
|
};
|
|
274
290
|
|
|
291
|
+
Object.defineProperty(exports, "createModuleFederationConfig", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: function () { return enhanced.createModuleFederationConfig; }
|
|
294
|
+
});
|
|
275
295
|
Object.defineProperty(exports, "PLUGIN_NAME", {
|
|
276
296
|
enumerable: true,
|
|
277
297
|
get: function () { return rspack.PLUGIN_NAME; }
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseOptions } from '@module-federation/enhanced';
|
|
2
|
+
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
2
3
|
import { PLUGIN_NAME, ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
3
4
|
export { PLUGIN_NAME } from '@module-federation/enhanced/rspack';
|
|
4
5
|
import { createLogger, isRequiredVersion } from '@module-federation/sdk';
|
|
@@ -6,7 +7,7 @@ import { autoDeleteSplitChunkCacheGroups, isRegExp } from './utils.esm.js';
|
|
|
6
7
|
import 'util';
|
|
7
8
|
|
|
8
9
|
var name = "@module-federation/rsbuild-plugin";
|
|
9
|
-
var version = "0.
|
|
10
|
+
var version = "0.11.0";
|
|
10
11
|
var description = "Module Federation plugin for Rsbuild";
|
|
11
12
|
var homepage = "https://module-federation.io";
|
|
12
13
|
var bugs = {
|
|
@@ -123,14 +124,22 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
123
124
|
var RSBUILD_PLUGIN_MODULE_FEDERATION_NAME = 'rsbuild:module-federation-enhanced';
|
|
124
125
|
var RSPACK_PLUGIN_MODULE_FEDERATION_NAME = 'module-federation';
|
|
125
126
|
var LIB_FORMAT = [
|
|
126
|
-
'commonjs',
|
|
127
127
|
'umd',
|
|
128
128
|
'modern-module'
|
|
129
129
|
];
|
|
130
|
+
function isStoryBook(rsbuildConfig) {
|
|
131
|
+
var _rsbuildConfig_plugins;
|
|
132
|
+
if ((_rsbuildConfig_plugins = rsbuildConfig.plugins) === null || _rsbuildConfig_plugins === void 0 ? void 0 : _rsbuildConfig_plugins.find(function(p) {
|
|
133
|
+
return p && 'name' in p && p.name === 'module-federation-storybook-plugin';
|
|
134
|
+
})) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
130
138
|
function isMFFormat(bundlerConfig) {
|
|
131
139
|
var _bundlerConfig_output;
|
|
132
140
|
var library = (_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.library;
|
|
133
|
-
return !((typeof library === "undefined" ? "undefined" : _type_of(library)) === 'object' && !Array.isArray(library) && 'type' in library &&
|
|
141
|
+
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
|
|
142
|
+
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type)));
|
|
134
143
|
}
|
|
135
144
|
var pluginModuleFederation = function(moduleFederationOptions) {
|
|
136
145
|
return {
|
|
@@ -160,10 +169,12 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
160
169
|
bundlerConfigs.forEach(function(bundlerConfig) {
|
|
161
170
|
if (!isMFFormat(bundlerConfig)) {
|
|
162
171
|
return;
|
|
172
|
+
} else if (isStoryBook(api.getRsbuildConfig())) {
|
|
173
|
+
bundlerConfig.output.uniqueName = "".concat(moduleFederationOptions.name, "-storybook-host");
|
|
163
174
|
} else {
|
|
164
|
-
var _bundlerConfig_output, _bundlerConfig_output1;
|
|
175
|
+
var _bundlerConfig_optimization, _bundlerConfig_output, _bundlerConfig_output1;
|
|
165
176
|
// mf
|
|
166
|
-
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig);
|
|
177
|
+
autoDeleteSplitChunkCacheGroups(moduleFederationOptions, bundlerConfig === null || bundlerConfig === void 0 ? void 0 : (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks);
|
|
167
178
|
var externals = bundlerConfig.externals;
|
|
168
179
|
if (Array.isArray(externals)) {
|
|
169
180
|
var sharedModules = new Set();
|
|
@@ -231,6 +242,9 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
231
242
|
if (!bundlerConfig.plugins.find(function(p) {
|
|
232
243
|
return p && p.name === PLUGIN_NAME;
|
|
233
244
|
})) {
|
|
245
|
+
if (!moduleFederationOptions.shareStrategy) {
|
|
246
|
+
moduleFederationOptions.shareStrategy = 'loaded-first';
|
|
247
|
+
}
|
|
234
248
|
bundlerConfig.plugins.push(new ModuleFederationPlugin(moduleFederationOptions));
|
|
235
249
|
}
|
|
236
250
|
}
|
|
@@ -238,6 +252,10 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
238
252
|
});
|
|
239
253
|
// dev config only works on format: 'mf'
|
|
240
254
|
api.modifyRsbuildConfig(function(config) {
|
|
255
|
+
// skip storybook
|
|
256
|
+
if (isStoryBook(config)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
241
259
|
// Change some default configs for remote modules
|
|
242
260
|
if (moduleFederationOptions.exposes) {
|
|
243
261
|
var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
@@ -262,8 +280,7 @@ var pluginModuleFederation = function(moduleFederationOptions) {
|
|
|
262
280
|
// Module Federation runtime uses ES6+ syntax,
|
|
263
281
|
// adding to include and let SWC transform it
|
|
264
282
|
config.source.include = _to_consumable_array(config.source.include || []).concat([
|
|
265
|
-
/@module-federation[\\/]
|
|
266
|
-
/@module-federation[\\/]runtime/
|
|
283
|
+
/@module-federation[\\/]/
|
|
267
284
|
]);
|
|
268
285
|
return config;
|
|
269
286
|
});
|
package/dist/src/cli/index.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ declare const RSPACK_PLUGIN_MODULE_FEDERATION_NAME = "module-federation";
|
|
|
8
8
|
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, RSPACK_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, };
|
|
9
9
|
export declare function isMFFormat(bundlerConfig: Rspack.Configuration): boolean;
|
|
10
10
|
export declare const pluginModuleFederation: (moduleFederationOptions: ModuleFederationOptions) => RsbuildPlugin;
|
|
11
|
+
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,49 @@
|
|
|
1
1
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
2
|
import type { Rspack } from '@rsbuild/core';
|
|
3
|
-
|
|
3
|
+
type OptimizationConfig = Rspack.Configuration['optimization'];
|
|
4
|
+
type SplitChunksConfig = NonNullable<OptimizationConfig>['splitChunks'];
|
|
5
|
+
export declare function autoDeleteSplitChunkCacheGroups(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, splitChunks: SplitChunksConfig): {
|
|
6
|
+
name?: string | false | ((args_0: Rspack.Module | undefined, ...args: unknown[]) => unknown) | undefined;
|
|
7
|
+
chunks?: RegExp | "all" | "initial" | "async" | ((args_0: Rspack.Chunk, ...args: unknown[]) => boolean) | undefined;
|
|
8
|
+
usedExports?: boolean | undefined;
|
|
9
|
+
maxSize?: number | Record<string, number> | undefined;
|
|
10
|
+
defaultSizeTypes?: string[] | undefined;
|
|
11
|
+
minChunks?: number | undefined;
|
|
12
|
+
minSize?: number | Record<string, number> | undefined;
|
|
13
|
+
maxAsyncSize?: number | Record<string, number> | undefined;
|
|
14
|
+
maxInitialSize?: number | Record<string, number> | undefined;
|
|
15
|
+
maxAsyncRequests?: number | undefined;
|
|
16
|
+
maxInitialRequests?: number | undefined;
|
|
17
|
+
automaticNameDelimiter?: string | undefined;
|
|
18
|
+
cacheGroups?: Record<string, false | {
|
|
19
|
+
type?: string | RegExp | undefined;
|
|
20
|
+
filename?: string | undefined;
|
|
21
|
+
name?: string | false | ((args_0: Rspack.Module | undefined, ...args: unknown[]) => unknown) | undefined;
|
|
22
|
+
priority?: number | undefined;
|
|
23
|
+
chunks?: RegExp | "all" | "initial" | "async" | ((args_0: Rspack.Chunk, ...args: unknown[]) => boolean) | undefined;
|
|
24
|
+
usedExports?: boolean | undefined;
|
|
25
|
+
test?: string | RegExp | ((args_0: Rspack.Module, ...args: unknown[]) => unknown) | undefined;
|
|
26
|
+
enforce?: boolean | undefined;
|
|
27
|
+
maxSize?: number | Record<string, number> | undefined;
|
|
28
|
+
reuseExistingChunk?: boolean | undefined;
|
|
29
|
+
idHint?: string | undefined;
|
|
30
|
+
defaultSizeTypes?: string[] | undefined;
|
|
31
|
+
minChunks?: number | undefined;
|
|
32
|
+
minSize?: number | Record<string, number> | undefined;
|
|
33
|
+
maxAsyncSize?: number | Record<string, number> | undefined;
|
|
34
|
+
maxInitialSize?: number | Record<string, number> | undefined;
|
|
35
|
+
maxAsyncRequests?: number | undefined;
|
|
36
|
+
maxInitialRequests?: number | undefined;
|
|
37
|
+
automaticNameDelimiter?: string | undefined;
|
|
38
|
+
}> | undefined;
|
|
39
|
+
fallbackCacheGroup?: {
|
|
40
|
+
chunks?: RegExp | "all" | "initial" | "async" | ((args_0: Rspack.Chunk, ...args: unknown[]) => boolean) | undefined;
|
|
41
|
+
maxSize?: number | undefined;
|
|
42
|
+
minSize?: number | undefined;
|
|
43
|
+
maxAsyncSize?: number | undefined;
|
|
44
|
+
maxInitialSize?: number | undefined;
|
|
45
|
+
automaticNameDelimiter?: string | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
hidePathInfo?: boolean | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
export {};
|
package/dist/utils.cjs.js
CHANGED
|
@@ -34,12 +34,11 @@ var SHARED_SPLIT_CHUNK_MAP = {
|
|
|
34
34
|
'@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
|
|
35
35
|
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
36
36
|
};
|
|
37
|
-
function autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
38
|
-
var _bundlerConfig_optimization;
|
|
37
|
+
function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
|
|
39
38
|
if (!mfConfig.shared) {
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
|
-
if (!
|
|
41
|
+
if (!splitChunks || !(splitChunks === null || splitChunks === void 0 ? void 0 : splitChunks.cacheGroups)) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
var arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
|
|
@@ -51,8 +50,8 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
51
50
|
if (!splitChunkKey) {
|
|
52
51
|
continue;
|
|
53
52
|
}
|
|
54
|
-
if (
|
|
55
|
-
delete
|
|
53
|
+
if (splitChunks.cacheGroups[splitChunkKey]) {
|
|
54
|
+
delete splitChunks.cacheGroups[splitChunkKey];
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
} catch (err) {
|
|
@@ -69,6 +68,7 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
}
|
|
71
|
+
return splitChunks;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
function isRegExp(target) {
|
package/dist/utils.esm.js
CHANGED
|
@@ -32,12 +32,11 @@ var SHARED_SPLIT_CHUNK_MAP = {
|
|
|
32
32
|
'@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI,
|
|
33
33
|
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
34
34
|
};
|
|
35
|
-
function autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
36
|
-
var _bundlerConfig_optimization;
|
|
35
|
+
function autoDeleteSplitChunkCacheGroups(mfConfig, splitChunks) {
|
|
37
36
|
if (!mfConfig.shared) {
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
|
-
if (!
|
|
39
|
+
if (!splitChunks || !(splitChunks === null || splitChunks === void 0 ? void 0 : splitChunks.cacheGroups)) {
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
42
|
var arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
|
|
@@ -49,8 +48,8 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
49
48
|
if (!splitChunkKey) {
|
|
50
49
|
continue;
|
|
51
50
|
}
|
|
52
|
-
if (
|
|
53
|
-
delete
|
|
51
|
+
if (splitChunks.cacheGroups[splitChunkKey]) {
|
|
52
|
+
delete splitChunks.cacheGroups[splitChunkKey];
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
} catch (err) {
|
|
@@ -67,6 +66,7 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
}
|
|
69
|
+
return splitChunks;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function isRegExp(target) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/rsbuild-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Module Federation plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://module-federation.io",
|
|
6
6
|
"bugs": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@module-federation/sdk": "0.
|
|
44
|
-
"@module-federation/enhanced": "0.
|
|
43
|
+
"@module-federation/sdk": "0.11.0",
|
|
44
|
+
"@module-federation/enhanced": "0.11.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@rsbuild/core": "^1.0.19"
|