@module-federation/rspack 2.1.0 → 2.2.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.
|
@@ -2,6 +2,9 @@ import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
|
2
2
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
3
|
import { RemoteEntryPlugin } from './RemoteEntryPlugin';
|
|
4
4
|
export declare const PLUGIN_NAME = "RspackModuleFederationPlugin";
|
|
5
|
+
type ResolveFn = typeof require.resolve;
|
|
6
|
+
export declare function resolveRspackRuntimeImplementation(implementation?: string, resolve?: ResolveFn): string;
|
|
7
|
+
export declare function resolveRspackRuntimeAlias(implementation: string, resolve?: ResolveFn): string;
|
|
5
8
|
export declare class ModuleFederationPlugin implements RspackPluginInstance {
|
|
6
9
|
readonly name = "RspackModuleFederationPlugin";
|
|
7
10
|
private _options;
|
|
@@ -56,6 +56,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
56
56
|
ModuleFederationPlugin: () => (/* binding */ ModuleFederationPlugin),
|
|
57
57
|
GetPublicPathPlugin: () => (/* binding */ GetPublicPathPlugin),
|
|
58
58
|
PLUGIN_NAME: () => (/* binding */ PLUGIN_NAME),
|
|
59
|
+
resolveRspackRuntimeImplementation: () => (/* binding */ resolveRspackRuntimeImplementation),
|
|
60
|
+
resolveRspackRuntimeAlias: () => (/* binding */ resolveRspackRuntimeAlias),
|
|
59
61
|
TreeShakingSharedPlugin: () => (/* reexport */ external_TreeShakingSharedPlugin_js_namespaceObject.TreeShakingSharedPlugin)
|
|
60
62
|
});
|
|
61
63
|
|
|
@@ -93,8 +95,42 @@ const external_TreeShakingSharedPlugin_js_namespaceObject = require("./TreeShaki
|
|
|
93
95
|
|
|
94
96
|
|
|
95
97
|
|
|
96
|
-
const RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
|
|
97
98
|
const PLUGIN_NAME = 'RspackModuleFederationPlugin';
|
|
99
|
+
function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
|
|
100
|
+
const candidates = [
|
|
101
|
+
spec.bundler,
|
|
102
|
+
spec.esm,
|
|
103
|
+
spec.cjs
|
|
104
|
+
];
|
|
105
|
+
const modulePaths = implementation ? [
|
|
106
|
+
implementation
|
|
107
|
+
] : undefined;
|
|
108
|
+
let lastError;
|
|
109
|
+
for (const candidate of candidates){
|
|
110
|
+
try {
|
|
111
|
+
return modulePaths ? resolve(candidate, {
|
|
112
|
+
paths: modulePaths
|
|
113
|
+
}) : resolve(candidate);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
lastError = error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw lastError;
|
|
119
|
+
}
|
|
120
|
+
function resolveRspackRuntimeImplementation(implementation, resolve = require.resolve) {
|
|
121
|
+
return resolveRuntimeEntry({
|
|
122
|
+
bundler: '@module-federation/runtime-tools/bundler',
|
|
123
|
+
esm: '@module-federation/runtime-tools/dist/index.js',
|
|
124
|
+
cjs: '@module-federation/runtime-tools/dist/index.cjs'
|
|
125
|
+
}, implementation, resolve);
|
|
126
|
+
}
|
|
127
|
+
function resolveRspackRuntimeAlias(implementation, resolve = require.resolve) {
|
|
128
|
+
return resolveRuntimeEntry({
|
|
129
|
+
bundler: '@module-federation/runtime/bundler',
|
|
130
|
+
esm: '@module-federation/runtime/dist/index.js',
|
|
131
|
+
cjs: '@module-federation/runtime/dist/index.cjs'
|
|
132
|
+
}, implementation, resolve);
|
|
133
|
+
}
|
|
98
134
|
class ModuleFederationPlugin {
|
|
99
135
|
_patchBundlerConfig(compiler) {
|
|
100
136
|
var _experiments_optimization;
|
|
@@ -148,7 +184,7 @@ class ModuleFederationPlugin {
|
|
|
148
184
|
// must before ModuleFederationPlugin
|
|
149
185
|
new external_RemoteEntryPlugin_js_namespaceObject.RemoteEntryPlugin(options).apply(compiler);
|
|
150
186
|
if ((_options_experiments = options.experiments) === null || _options_experiments === void 0 ? void 0 : _options_experiments.provideExternalRuntime) {
|
|
151
|
-
if (
|
|
187
|
+
if (containerManager.enable) {
|
|
152
188
|
throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
|
|
153
189
|
}
|
|
154
190
|
const runtimePlugins = options.runtimePlugins || [];
|
|
@@ -160,7 +196,7 @@ class ModuleFederationPlugin {
|
|
|
160
196
|
'@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
|
|
161
197
|
}).apply(compiler);
|
|
162
198
|
}
|
|
163
|
-
const implementationPath = options.implementation
|
|
199
|
+
const implementationPath = options.implementation ? options.implementation : resolveRspackRuntimeImplementation();
|
|
164
200
|
options.implementation = implementationPath;
|
|
165
201
|
let disableManifest = options.manifest === false;
|
|
166
202
|
let disableDts = options.dts === false;
|
|
@@ -182,34 +218,22 @@ class ModuleFederationPlugin {
|
|
|
182
218
|
}
|
|
183
219
|
}
|
|
184
220
|
new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
193
|
-
} catch {}
|
|
194
|
-
}
|
|
195
|
-
throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry from ${candidates.join(', ')}`);
|
|
196
|
-
};
|
|
197
|
-
const runtimeESMPath = resolveRuntimePath([
|
|
198
|
-
'@module-federation/runtime/dist/index.js',
|
|
199
|
-
'@module-federation/runtime/dist/index.esm.js',
|
|
200
|
-
'@module-federation/runtime/dist/index.cjs',
|
|
201
|
-
'@module-federation/runtime/dist/index.cjs.cjs',
|
|
202
|
-
'@module-federation/runtime'
|
|
203
|
-
]);
|
|
221
|
+
let runtimePath;
|
|
222
|
+
try {
|
|
223
|
+
runtimePath = resolveRspackRuntimeAlias(implementationPath);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
226
|
+
throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry (paths: [${implementationPath}]): ${detail}`);
|
|
227
|
+
}
|
|
204
228
|
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', ()=>{
|
|
205
229
|
compiler.options.resolve.alias = {
|
|
206
230
|
...compiler.options.resolve.alias,
|
|
207
|
-
'@module-federation/runtime$':
|
|
231
|
+
'@module-federation/runtime$': runtimePath
|
|
208
232
|
};
|
|
209
233
|
});
|
|
210
234
|
if (!disableManifest) {
|
|
211
235
|
this._statsPlugin = new manifest_namespaceObject.StatsPlugin(options, {
|
|
212
|
-
pluginVersion: "2.
|
|
236
|
+
pluginVersion: "2.2.0",
|
|
213
237
|
bundler: 'rspack'
|
|
214
238
|
});
|
|
215
239
|
// @ts-ignore
|
|
@@ -357,8 +381,10 @@ exports.GetPublicPathPlugin = __webpack_exports__.GetPublicPathPlugin;
|
|
|
357
381
|
exports.ModuleFederationPlugin = __webpack_exports__.ModuleFederationPlugin;
|
|
358
382
|
exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
|
|
359
383
|
exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
|
|
384
|
+
exports.resolveRspackRuntimeAlias = __webpack_exports__.resolveRspackRuntimeAlias;
|
|
385
|
+
exports.resolveRspackRuntimeImplementation = __webpack_exports__.resolveRspackRuntimeImplementation;
|
|
360
386
|
for(var __webpack_i__ in __webpack_exports__) {
|
|
361
|
-
if(["GetPublicPathPlugin","ModuleFederationPlugin","PLUGIN_NAME","TreeShakingSharedPlugin"].indexOf(__webpack_i__) === -1) {
|
|
387
|
+
if(["GetPublicPathPlugin","ModuleFederationPlugin","PLUGIN_NAME","TreeShakingSharedPlugin","resolveRspackRuntimeAlias","resolveRspackRuntimeImplementation"].indexOf(__webpack_i__) === -1) {
|
|
362
388
|
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
363
389
|
}
|
|
364
390
|
}
|
|
@@ -39,8 +39,42 @@ import { TreeShakingSharedPlugin } from "./TreeShakingSharedPlugin.mjs";
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
const RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
|
|
43
42
|
const PLUGIN_NAME = 'RspackModuleFederationPlugin';
|
|
43
|
+
function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
|
|
44
|
+
const candidates = [
|
|
45
|
+
spec.bundler,
|
|
46
|
+
spec.esm,
|
|
47
|
+
spec.cjs
|
|
48
|
+
];
|
|
49
|
+
const modulePaths = implementation ? [
|
|
50
|
+
implementation
|
|
51
|
+
] : undefined;
|
|
52
|
+
let lastError;
|
|
53
|
+
for (const candidate of candidates){
|
|
54
|
+
try {
|
|
55
|
+
return modulePaths ? resolve(candidate, {
|
|
56
|
+
paths: modulePaths
|
|
57
|
+
}) : resolve(candidate);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
lastError = error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw lastError;
|
|
63
|
+
}
|
|
64
|
+
function resolveRspackRuntimeImplementation(implementation, resolve = require.resolve) {
|
|
65
|
+
return resolveRuntimeEntry({
|
|
66
|
+
bundler: '@module-federation/runtime-tools/bundler',
|
|
67
|
+
esm: '@module-federation/runtime-tools/dist/index.js',
|
|
68
|
+
cjs: '@module-federation/runtime-tools/dist/index.cjs'
|
|
69
|
+
}, implementation, resolve);
|
|
70
|
+
}
|
|
71
|
+
function resolveRspackRuntimeAlias(implementation, resolve = require.resolve) {
|
|
72
|
+
return resolveRuntimeEntry({
|
|
73
|
+
bundler: '@module-federation/runtime/bundler',
|
|
74
|
+
esm: '@module-federation/runtime/dist/index.js',
|
|
75
|
+
cjs: '@module-federation/runtime/dist/index.cjs'
|
|
76
|
+
}, implementation, resolve);
|
|
77
|
+
}
|
|
44
78
|
class ModuleFederationPlugin {
|
|
45
79
|
_patchBundlerConfig(compiler) {
|
|
46
80
|
var _experiments_optimization;
|
|
@@ -94,7 +128,7 @@ class ModuleFederationPlugin {
|
|
|
94
128
|
// must before ModuleFederationPlugin
|
|
95
129
|
new RemoteEntryPlugin(options).apply(compiler);
|
|
96
130
|
if ((_options_experiments = options.experiments) === null || _options_experiments === void 0 ? void 0 : _options_experiments.provideExternalRuntime) {
|
|
97
|
-
if (
|
|
131
|
+
if (containerManager.enable) {
|
|
98
132
|
throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
|
|
99
133
|
}
|
|
100
134
|
const runtimePlugins = options.runtimePlugins || [];
|
|
@@ -106,7 +140,7 @@ class ModuleFederationPlugin {
|
|
|
106
140
|
'@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
|
|
107
141
|
}).apply(compiler);
|
|
108
142
|
}
|
|
109
|
-
const implementationPath = options.implementation
|
|
143
|
+
const implementationPath = options.implementation ? options.implementation : resolveRspackRuntimeImplementation();
|
|
110
144
|
options.implementation = implementationPath;
|
|
111
145
|
let disableManifest = options.manifest === false;
|
|
112
146
|
let disableDts = options.dts === false;
|
|
@@ -128,34 +162,22 @@ class ModuleFederationPlugin {
|
|
|
128
162
|
}
|
|
129
163
|
}
|
|
130
164
|
new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
139
|
-
} catch {}
|
|
140
|
-
}
|
|
141
|
-
throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry from ${candidates.join(', ')}`);
|
|
142
|
-
};
|
|
143
|
-
const runtimeESMPath = resolveRuntimePath([
|
|
144
|
-
'@module-federation/runtime/dist/index.js',
|
|
145
|
-
'@module-federation/runtime/dist/index.esm.js',
|
|
146
|
-
'@module-federation/runtime/dist/index.cjs',
|
|
147
|
-
'@module-federation/runtime/dist/index.cjs.cjs',
|
|
148
|
-
'@module-federation/runtime'
|
|
149
|
-
]);
|
|
165
|
+
let runtimePath;
|
|
166
|
+
try {
|
|
167
|
+
runtimePath = resolveRspackRuntimeAlias(implementationPath);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
170
|
+
throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry (paths: [${implementationPath}]): ${detail}`);
|
|
171
|
+
}
|
|
150
172
|
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', ()=>{
|
|
151
173
|
compiler.options.resolve.alias = {
|
|
152
174
|
...compiler.options.resolve.alias,
|
|
153
|
-
'@module-federation/runtime$':
|
|
175
|
+
'@module-federation/runtime$': runtimePath
|
|
154
176
|
};
|
|
155
177
|
});
|
|
156
178
|
if (!disableManifest) {
|
|
157
179
|
this._statsPlugin = new StatsPlugin(options, {
|
|
158
|
-
pluginVersion: "2.
|
|
180
|
+
pluginVersion: "2.2.0",
|
|
159
181
|
bundler: 'rspack'
|
|
160
182
|
});
|
|
161
183
|
// @ts-ignore
|
|
@@ -299,4 +321,4 @@ class ModuleFederationPlugin {
|
|
|
299
321
|
const GetPublicPathPlugin = RemoteEntryPlugin;
|
|
300
322
|
|
|
301
323
|
|
|
302
|
-
export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME, TreeShakingSharedPlugin };
|
|
324
|
+
export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME, TreeShakingSharedPlugin, resolveRspackRuntimeAlias, resolveRspackRuntimeImplementation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/rspack",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Module Federation",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"btoa": "1.2.1",
|
|
28
|
-
"@module-federation/bridge-react-webpack-plugin": "2.
|
|
29
|
-
"@module-federation/managers": "2.
|
|
30
|
-
"@module-federation/manifest": "2.
|
|
31
|
-
"@module-federation/runtime-tools": "2.
|
|
32
|
-
"@module-federation/
|
|
33
|
-
"@module-federation/
|
|
34
|
-
"@module-federation/
|
|
28
|
+
"@module-federation/bridge-react-webpack-plugin": "2.2.0",
|
|
29
|
+
"@module-federation/managers": "2.2.0",
|
|
30
|
+
"@module-federation/manifest": "2.2.0",
|
|
31
|
+
"@module-federation/runtime-tools": "2.2.0",
|
|
32
|
+
"@module-federation/inject-external-runtime-core-plugin": "2.2.0",
|
|
33
|
+
"@module-federation/dts-plugin": "2.2.0",
|
|
34
|
+
"@module-federation/sdk": "2.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@rspack/core": "^1.0.2"
|
|
@@ -93,5 +93,12 @@
|
|
|
93
93
|
"vue-tsc": {
|
|
94
94
|
"optional": true
|
|
95
95
|
}
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "rslib build",
|
|
99
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
100
|
+
"test": "pnpm exec jest --config jest.config.js --passWithNoTests",
|
|
101
|
+
"test:ci": "pnpm exec jest --config jest.config.js --passWithNoTests --ci --coverage",
|
|
102
|
+
"pre-release": "pnpm run test && pnpm run build"
|
|
96
103
|
}
|
|
97
104
|
}
|