@module-federation/rspack 0.0.0-fix-lazy-comile-20250925082726
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/LICENSE +21 -0
- package/dist/index.cjs.js +13 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.d.ts +1 -0
- package/dist/index.esm.mjs +8 -0
- package/dist/index.esm.mjs.map +1 -0
- package/dist/plugin.cjs.js +301 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.esm.d.ts +1 -0
- package/dist/plugin.esm.mjs +297 -0
- package/dist/plugin.esm.mjs.map +1 -0
- package/dist/remote-entry-plugin.cjs.js +97 -0
- package/dist/remote-entry-plugin.cjs.js.map +1 -0
- package/dist/remote-entry-plugin.d.ts +1 -0
- package/dist/remote-entry-plugin.esm.d.ts +1 -0
- package/dist/remote-entry-plugin.esm.mjs +95 -0
- package/dist/remote-entry-plugin.esm.mjs.map +1 -0
- package/dist/src/ModuleFederationPlugin.d.ts +16 -0
- package/dist/src/RemoteEntryPlugin.d.ts +9 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/logger.d.ts +2 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present hanric(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@module-federation/rspack` Documentation
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present hanric(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var plugin = require('./plugin.cjs.js');
|
|
4
|
+
var core = require('@rspack/core');
|
|
5
|
+
|
|
6
|
+
var ContainerPlugin = core.container.ContainerPlugin;
|
|
7
|
+
var ContainerReferencePlugin = core.container.ContainerReferencePlugin;
|
|
8
|
+
|
|
9
|
+
exports.ModuleFederationPlugin = plugin.ModuleFederationPlugin;
|
|
10
|
+
exports.PLUGIN_NAME = plugin.PLUGIN_NAME;
|
|
11
|
+
exports.ContainerPlugin = ContainerPlugin;
|
|
12
|
+
exports.ContainerReferencePlugin = ContainerReferencePlugin;
|
|
13
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ModuleFederationPlugin, PLUGIN_NAME } from './plugin.esm.mjs';
|
|
2
|
+
import { container } from '@rspack/core';
|
|
3
|
+
|
|
4
|
+
var ContainerPlugin = container.ContainerPlugin;
|
|
5
|
+
var ContainerReferencePlugin = container.ContainerReferencePlugin;
|
|
6
|
+
|
|
7
|
+
export { ContainerPlugin, ContainerReferencePlugin };
|
|
8
|
+
//# sourceMappingURL=index.esm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sdk = require('@module-federation/sdk');
|
|
4
|
+
var manifest = require('@module-federation/manifest');
|
|
5
|
+
var managers = require('@module-federation/managers');
|
|
6
|
+
var dtsPlugin = require('@module-federation/dts-plugin');
|
|
7
|
+
var ReactBridgePlugin = require('@module-federation/bridge-react-webpack-plugin');
|
|
8
|
+
var path = require('node:path');
|
|
9
|
+
var fs = require('node:fs');
|
|
10
|
+
var remoteEntryPlugin = require('./remote-entry-plugin.cjs.js');
|
|
11
|
+
|
|
12
|
+
function _class_call_check(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
return Constructor;
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _instanceof(left, right) {
|
|
44
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
45
|
+
return !!right[Symbol.hasInstance](left);
|
|
46
|
+
} else {
|
|
47
|
+
return left instanceof right;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function _object_spread(target) {
|
|
51
|
+
for(var i = 1; i < arguments.length; i++){
|
|
52
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
53
|
+
var ownKeys = Object.keys(source);
|
|
54
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
55
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
56
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
ownKeys.forEach(function(key) {
|
|
60
|
+
_define_property(target, key, source[key]);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return target;
|
|
64
|
+
}
|
|
65
|
+
function ownKeys(object, enumerableOnly) {
|
|
66
|
+
var keys = Object.keys(object);
|
|
67
|
+
if (Object.getOwnPropertySymbols) {
|
|
68
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
69
|
+
keys.push.apply(keys, symbols);
|
|
70
|
+
}
|
|
71
|
+
return keys;
|
|
72
|
+
}
|
|
73
|
+
function _object_spread_props(target, source) {
|
|
74
|
+
source = source != null ? source : {};
|
|
75
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
76
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
77
|
+
} else {
|
|
78
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
79
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
function _type_of(obj) {
|
|
85
|
+
"@swc/helpers - typeof";
|
|
86
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
87
|
+
}
|
|
88
|
+
var RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
|
|
89
|
+
var PLUGIN_NAME = 'RspackModuleFederationPlugin';
|
|
90
|
+
var ModuleFederationPlugin = /*#__PURE__*/ function() {
|
|
91
|
+
function ModuleFederationPlugin(options) {
|
|
92
|
+
_class_call_check(this, ModuleFederationPlugin);
|
|
93
|
+
this.name = PLUGIN_NAME;
|
|
94
|
+
this._options = options;
|
|
95
|
+
}
|
|
96
|
+
_create_class(ModuleFederationPlugin, [
|
|
97
|
+
{
|
|
98
|
+
key: "_patchBundlerConfig",
|
|
99
|
+
value: function _patchBundlerConfig(compiler) {
|
|
100
|
+
var _experiments_optimization;
|
|
101
|
+
var _this__options = this._options, name = _this__options.name, experiments = _this__options.experiments;
|
|
102
|
+
var definePluginOptions = {};
|
|
103
|
+
if (name) {
|
|
104
|
+
definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(sdk.composeKeyWithSeparator(name, managers.utils.getBuildVersion()));
|
|
105
|
+
}
|
|
106
|
+
var _experiments_optimization_disableSnapshot;
|
|
107
|
+
// Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
|
|
108
|
+
var disableSnapshot = (_experiments_optimization_disableSnapshot = experiments === null || experiments === void 0 ? void 0 : (_experiments_optimization = experiments.optimization) === null || _experiments_optimization === void 0 ? void 0 : _experiments_optimization.disableSnapshot) !== null && _experiments_optimization_disableSnapshot !== void 0 ? _experiments_optimization_disableSnapshot : false;
|
|
109
|
+
definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] = disableSnapshot;
|
|
110
|
+
// Determine ENV_TARGET: only if manually specified in experiments.optimization.target
|
|
111
|
+
if ((experiments === null || experiments === void 0 ? void 0 : experiments.optimization) && _type_of(experiments.optimization) === 'object' && experiments.optimization !== null && 'target' in experiments.optimization) {
|
|
112
|
+
var manualTarget = experiments.optimization.target;
|
|
113
|
+
// Ensure the target is one of the expected values before setting
|
|
114
|
+
if (manualTarget === 'web' || manualTarget === 'node') {
|
|
115
|
+
definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// No inference for ENV_TARGET. If not manually set and valid, it's not defined.
|
|
119
|
+
new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
key: "_checkSingleton",
|
|
124
|
+
value: function _checkSingleton(compiler) {
|
|
125
|
+
var _this = this;
|
|
126
|
+
var count = 0;
|
|
127
|
+
compiler.options.plugins.forEach(function(p) {
|
|
128
|
+
if ((typeof p === "undefined" ? "undefined" : _type_of(p)) !== 'object' || !p) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (p['name'] === _this.name) {
|
|
132
|
+
count++;
|
|
133
|
+
if (count > 1) {
|
|
134
|
+
throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
key: "apply",
|
|
142
|
+
value: function apply(compiler) {
|
|
143
|
+
var _options_experiments, _options_experiments1;
|
|
144
|
+
var _this = this, options = _this._options;
|
|
145
|
+
if (!options.name) {
|
|
146
|
+
throw new Error('[ ModuleFederationPlugin ]: name is required');
|
|
147
|
+
}
|
|
148
|
+
this._checkSingleton(compiler);
|
|
149
|
+
this._patchBundlerConfig(compiler);
|
|
150
|
+
var containerManager = new managers.ContainerManager();
|
|
151
|
+
containerManager.init(options);
|
|
152
|
+
if (containerManager.enable) {
|
|
153
|
+
this._patchChunkSplit(compiler, options.name);
|
|
154
|
+
}
|
|
155
|
+
// must before ModuleFederationPlugin
|
|
156
|
+
new remoteEntryPlugin.RemoteEntryPlugin(options).apply(compiler);
|
|
157
|
+
if ((_options_experiments = options.experiments) === null || _options_experiments === void 0 ? void 0 : _options_experiments.provideExternalRuntime) {
|
|
158
|
+
if (options.exposes) {
|
|
159
|
+
throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
|
|
160
|
+
}
|
|
161
|
+
var runtimePlugins = options.runtimePlugins || [];
|
|
162
|
+
options.runtimePlugins = runtimePlugins.concat(require.resolve('@module-federation/inject-external-runtime-core-plugin'));
|
|
163
|
+
}
|
|
164
|
+
if (((_options_experiments1 = options.experiments) === null || _options_experiments1 === void 0 ? void 0 : _options_experiments1.externalRuntime) === true) {
|
|
165
|
+
var Externals = compiler.webpack.ExternalsPlugin;
|
|
166
|
+
new Externals(compiler.options.externalsType || 'global', {
|
|
167
|
+
'@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
|
|
168
|
+
}).apply(compiler);
|
|
169
|
+
}
|
|
170
|
+
options.implementation = options.implementation || RuntimeToolsPath;
|
|
171
|
+
var disableManifest = options.manifest === false;
|
|
172
|
+
var disableDts = options.dts === false;
|
|
173
|
+
if (!disableDts) {
|
|
174
|
+
var dtsPlugin$1 = new dtsPlugin.DtsPlugin(options);
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
dtsPlugin$1.apply(compiler);
|
|
177
|
+
dtsPlugin$1.addRuntimePlugins();
|
|
178
|
+
}
|
|
179
|
+
if (!disableManifest && options.exposes) {
|
|
180
|
+
try {
|
|
181
|
+
options.exposes = containerManager.containerPluginExposesOptions;
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (_instanceof(err, Error)) {
|
|
184
|
+
err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
|
|
185
|
+
}
|
|
186
|
+
console.warn(err);
|
|
187
|
+
disableManifest = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
|
|
191
|
+
var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.js', {
|
|
192
|
+
paths: [
|
|
193
|
+
options.implementation
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
|
|
197
|
+
compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
|
|
198
|
+
'@module-federation/runtime$': runtimeESMPath
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
if (!disableManifest) {
|
|
202
|
+
this._statsPlugin = new manifest.StatsPlugin(options, {
|
|
203
|
+
pluginVersion: "0.0.0-fix-lazy-comile-20250925082726",
|
|
204
|
+
bundler: 'rspack'
|
|
205
|
+
});
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
this._statsPlugin.apply(compiler);
|
|
208
|
+
}
|
|
209
|
+
// react bridge plugin
|
|
210
|
+
var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
|
|
211
|
+
var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
|
|
212
|
+
// Check whether react exists
|
|
213
|
+
if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
|
|
214
|
+
new ReactBridgePlugin({
|
|
215
|
+
moduleFederationOptions: this._options
|
|
216
|
+
}).apply(compiler);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
key: "_patchChunkSplit",
|
|
222
|
+
value: function _patchChunkSplit(compiler, name) {
|
|
223
|
+
var splitChunks = compiler.options.optimization.splitChunks;
|
|
224
|
+
var patchChunkSplit = function(cacheGroup) {
|
|
225
|
+
switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
|
|
226
|
+
case 'boolean':
|
|
227
|
+
case 'string':
|
|
228
|
+
case 'function':
|
|
229
|
+
break;
|
|
230
|
+
// cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
|
|
231
|
+
case 'object':
|
|
232
|
+
{
|
|
233
|
+
if (_instanceof(cacheGroup, RegExp)) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
if (!cacheGroup.chunks) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
if (typeof cacheGroup.chunks === 'function') {
|
|
240
|
+
var prevChunks = cacheGroup.chunks;
|
|
241
|
+
cacheGroup.chunks = function(chunk) {
|
|
242
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return prevChunks(chunk);
|
|
246
|
+
};
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
if (cacheGroup.chunks === 'all') {
|
|
250
|
+
cacheGroup.chunks = function(chunk) {
|
|
251
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
};
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (cacheGroup.chunks === 'initial') {
|
|
259
|
+
cacheGroup.chunks = function(chunk) {
|
|
260
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return chunk.isOnlyInitial();
|
|
264
|
+
};
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
if (!splitChunks) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
// 修改 splitChunk.chunks
|
|
275
|
+
patchChunkSplit(splitChunks);
|
|
276
|
+
var cacheGroups = splitChunks.cacheGroups;
|
|
277
|
+
if (!cacheGroups) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
// 修改 splitChunk.cacheGroups[key].chunks
|
|
281
|
+
Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
|
|
282
|
+
patchChunkSplit(cacheGroups[cacheGroupKey]);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
key: "statsResourceInfo",
|
|
288
|
+
get: function get() {
|
|
289
|
+
var _this__statsPlugin;
|
|
290
|
+
return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
]);
|
|
294
|
+
return ModuleFederationPlugin;
|
|
295
|
+
}();
|
|
296
|
+
var GetPublicPathPlugin = remoteEntryPlugin.RemoteEntryPlugin;
|
|
297
|
+
|
|
298
|
+
exports.GetPublicPathPlugin = GetPublicPathPlugin;
|
|
299
|
+
exports.ModuleFederationPlugin = ModuleFederationPlugin;
|
|
300
|
+
exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
301
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/ModuleFederationPlugin";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/ModuleFederationPlugin";
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { composeKeyWithSeparator } from '@module-federation/sdk';
|
|
2
|
+
import { StatsPlugin } from '@module-federation/manifest';
|
|
3
|
+
import { utils, ContainerManager } from '@module-federation/managers';
|
|
4
|
+
import { DtsPlugin } from '@module-federation/dts-plugin';
|
|
5
|
+
import ReactBridgePlugin from '@module-federation/bridge-react-webpack-plugin';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import { RemoteEntryPlugin } from './remote-entry-plugin.esm.mjs';
|
|
9
|
+
|
|
10
|
+
function _class_call_check(instance, Constructor) {
|
|
11
|
+
if (!(instance instanceof Constructor)) {
|
|
12
|
+
throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _defineProperties(target, props) {
|
|
16
|
+
for(var i = 0; i < props.length; i++){
|
|
17
|
+
var descriptor = props[i];
|
|
18
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
19
|
+
descriptor.configurable = true;
|
|
20
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
21
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
25
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
26
|
+
return Constructor;
|
|
27
|
+
}
|
|
28
|
+
function _define_property(obj, key, value) {
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
obj[key] = value;
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
function _instanceof(left, right) {
|
|
42
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
43
|
+
return !!right[Symbol.hasInstance](left);
|
|
44
|
+
} else {
|
|
45
|
+
return left instanceof right;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _object_spread(target) {
|
|
49
|
+
for(var i = 1; i < arguments.length; i++){
|
|
50
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
51
|
+
var ownKeys = Object.keys(source);
|
|
52
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
53
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
54
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
ownKeys.forEach(function(key) {
|
|
58
|
+
_define_property(target, key, source[key]);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
63
|
+
function ownKeys(object, enumerableOnly) {
|
|
64
|
+
var keys = Object.keys(object);
|
|
65
|
+
if (Object.getOwnPropertySymbols) {
|
|
66
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
67
|
+
keys.push.apply(keys, symbols);
|
|
68
|
+
}
|
|
69
|
+
return keys;
|
|
70
|
+
}
|
|
71
|
+
function _object_spread_props(target, source) {
|
|
72
|
+
source = source != null ? source : {};
|
|
73
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
+
} else {
|
|
76
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
function _type_of(obj) {
|
|
83
|
+
"@swc/helpers - typeof";
|
|
84
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
85
|
+
}
|
|
86
|
+
var RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
|
|
87
|
+
var PLUGIN_NAME = 'RspackModuleFederationPlugin';
|
|
88
|
+
var ModuleFederationPlugin = /*#__PURE__*/ function() {
|
|
89
|
+
function ModuleFederationPlugin(options) {
|
|
90
|
+
_class_call_check(this, ModuleFederationPlugin);
|
|
91
|
+
this.name = PLUGIN_NAME;
|
|
92
|
+
this._options = options;
|
|
93
|
+
}
|
|
94
|
+
_create_class(ModuleFederationPlugin, [
|
|
95
|
+
{
|
|
96
|
+
key: "_patchBundlerConfig",
|
|
97
|
+
value: function _patchBundlerConfig(compiler) {
|
|
98
|
+
var _experiments_optimization;
|
|
99
|
+
var _this__options = this._options, name = _this__options.name, experiments = _this__options.experiments;
|
|
100
|
+
var definePluginOptions = {};
|
|
101
|
+
if (name) {
|
|
102
|
+
definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(composeKeyWithSeparator(name, utils.getBuildVersion()));
|
|
103
|
+
}
|
|
104
|
+
var _experiments_optimization_disableSnapshot;
|
|
105
|
+
// Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
|
|
106
|
+
var disableSnapshot = (_experiments_optimization_disableSnapshot = experiments === null || experiments === void 0 ? void 0 : (_experiments_optimization = experiments.optimization) === null || _experiments_optimization === void 0 ? void 0 : _experiments_optimization.disableSnapshot) !== null && _experiments_optimization_disableSnapshot !== void 0 ? _experiments_optimization_disableSnapshot : false;
|
|
107
|
+
definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] = disableSnapshot;
|
|
108
|
+
// Determine ENV_TARGET: only if manually specified in experiments.optimization.target
|
|
109
|
+
if ((experiments === null || experiments === void 0 ? void 0 : experiments.optimization) && _type_of(experiments.optimization) === 'object' && experiments.optimization !== null && 'target' in experiments.optimization) {
|
|
110
|
+
var manualTarget = experiments.optimization.target;
|
|
111
|
+
// Ensure the target is one of the expected values before setting
|
|
112
|
+
if (manualTarget === 'web' || manualTarget === 'node') {
|
|
113
|
+
definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// No inference for ENV_TARGET. If not manually set and valid, it's not defined.
|
|
117
|
+
new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: "_checkSingleton",
|
|
122
|
+
value: function _checkSingleton(compiler) {
|
|
123
|
+
var _this = this;
|
|
124
|
+
var count = 0;
|
|
125
|
+
compiler.options.plugins.forEach(function(p) {
|
|
126
|
+
if ((typeof p === "undefined" ? "undefined" : _type_of(p)) !== 'object' || !p) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (p['name'] === _this.name) {
|
|
130
|
+
count++;
|
|
131
|
+
if (count > 1) {
|
|
132
|
+
throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: "apply",
|
|
140
|
+
value: function apply(compiler) {
|
|
141
|
+
var _options_experiments, _options_experiments1;
|
|
142
|
+
var _this = this, options = _this._options;
|
|
143
|
+
if (!options.name) {
|
|
144
|
+
throw new Error('[ ModuleFederationPlugin ]: name is required');
|
|
145
|
+
}
|
|
146
|
+
this._checkSingleton(compiler);
|
|
147
|
+
this._patchBundlerConfig(compiler);
|
|
148
|
+
var containerManager = new ContainerManager();
|
|
149
|
+
containerManager.init(options);
|
|
150
|
+
if (containerManager.enable) {
|
|
151
|
+
this._patchChunkSplit(compiler, options.name);
|
|
152
|
+
}
|
|
153
|
+
// must before ModuleFederationPlugin
|
|
154
|
+
new RemoteEntryPlugin(options).apply(compiler);
|
|
155
|
+
if ((_options_experiments = options.experiments) === null || _options_experiments === void 0 ? void 0 : _options_experiments.provideExternalRuntime) {
|
|
156
|
+
if (options.exposes) {
|
|
157
|
+
throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
|
|
158
|
+
}
|
|
159
|
+
var runtimePlugins = options.runtimePlugins || [];
|
|
160
|
+
options.runtimePlugins = runtimePlugins.concat(require.resolve('@module-federation/inject-external-runtime-core-plugin'));
|
|
161
|
+
}
|
|
162
|
+
if (((_options_experiments1 = options.experiments) === null || _options_experiments1 === void 0 ? void 0 : _options_experiments1.externalRuntime) === true) {
|
|
163
|
+
var Externals = compiler.webpack.ExternalsPlugin;
|
|
164
|
+
new Externals(compiler.options.externalsType || 'global', {
|
|
165
|
+
'@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
|
|
166
|
+
}).apply(compiler);
|
|
167
|
+
}
|
|
168
|
+
options.implementation = options.implementation || RuntimeToolsPath;
|
|
169
|
+
var disableManifest = options.manifest === false;
|
|
170
|
+
var disableDts = options.dts === false;
|
|
171
|
+
if (!disableDts) {
|
|
172
|
+
var dtsPlugin = new DtsPlugin(options);
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
dtsPlugin.apply(compiler);
|
|
175
|
+
dtsPlugin.addRuntimePlugins();
|
|
176
|
+
}
|
|
177
|
+
if (!disableManifest && options.exposes) {
|
|
178
|
+
try {
|
|
179
|
+
options.exposes = containerManager.containerPluginExposesOptions;
|
|
180
|
+
} catch (err) {
|
|
181
|
+
if (_instanceof(err, Error)) {
|
|
182
|
+
err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
|
|
183
|
+
}
|
|
184
|
+
console.warn(err);
|
|
185
|
+
disableManifest = true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
|
|
189
|
+
var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.js', {
|
|
190
|
+
paths: [
|
|
191
|
+
options.implementation
|
|
192
|
+
]
|
|
193
|
+
});
|
|
194
|
+
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
|
|
195
|
+
compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
|
|
196
|
+
'@module-federation/runtime$': runtimeESMPath
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
if (!disableManifest) {
|
|
200
|
+
this._statsPlugin = new StatsPlugin(options, {
|
|
201
|
+
pluginVersion: "0.0.0-fix-lazy-comile-20250925082726",
|
|
202
|
+
bundler: 'rspack'
|
|
203
|
+
});
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
this._statsPlugin.apply(compiler);
|
|
206
|
+
}
|
|
207
|
+
// react bridge plugin
|
|
208
|
+
var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
|
|
209
|
+
var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
|
|
210
|
+
// Check whether react exists
|
|
211
|
+
if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
|
|
212
|
+
new ReactBridgePlugin({
|
|
213
|
+
moduleFederationOptions: this._options
|
|
214
|
+
}).apply(compiler);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
key: "_patchChunkSplit",
|
|
220
|
+
value: function _patchChunkSplit(compiler, name) {
|
|
221
|
+
var splitChunks = compiler.options.optimization.splitChunks;
|
|
222
|
+
var patchChunkSplit = function(cacheGroup) {
|
|
223
|
+
switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
|
|
224
|
+
case 'boolean':
|
|
225
|
+
case 'string':
|
|
226
|
+
case 'function':
|
|
227
|
+
break;
|
|
228
|
+
// cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
|
|
229
|
+
case 'object':
|
|
230
|
+
{
|
|
231
|
+
if (_instanceof(cacheGroup, RegExp)) {
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
if (!cacheGroup.chunks) {
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
if (typeof cacheGroup.chunks === 'function') {
|
|
238
|
+
var prevChunks = cacheGroup.chunks;
|
|
239
|
+
cacheGroup.chunks = function(chunk) {
|
|
240
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return prevChunks(chunk);
|
|
244
|
+
};
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
if (cacheGroup.chunks === 'all') {
|
|
248
|
+
cacheGroup.chunks = function(chunk) {
|
|
249
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
};
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
if (cacheGroup.chunks === 'initial') {
|
|
257
|
+
cacheGroup.chunks = function(chunk) {
|
|
258
|
+
if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
return chunk.isOnlyInitial();
|
|
262
|
+
};
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
if (!splitChunks) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
// 修改 splitChunk.chunks
|
|
273
|
+
patchChunkSplit(splitChunks);
|
|
274
|
+
var cacheGroups = splitChunks.cacheGroups;
|
|
275
|
+
if (!cacheGroups) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
// 修改 splitChunk.cacheGroups[key].chunks
|
|
279
|
+
Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
|
|
280
|
+
patchChunkSplit(cacheGroups[cacheGroupKey]);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
key: "statsResourceInfo",
|
|
286
|
+
get: function get() {
|
|
287
|
+
var _this__statsPlugin;
|
|
288
|
+
return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
]);
|
|
292
|
+
return ModuleFederationPlugin;
|
|
293
|
+
}();
|
|
294
|
+
var GetPublicPathPlugin = RemoteEntryPlugin;
|
|
295
|
+
|
|
296
|
+
export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME };
|
|
297
|
+
//# sourceMappingURL=plugin.esm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.esm.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pBtoa = require('btoa');
|
|
4
|
+
var managers = require('@module-federation/managers');
|
|
5
|
+
var sdk = require('@module-federation/sdk');
|
|
6
|
+
|
|
7
|
+
var logger = sdk.createLogger('[ Module Federation Rspack Plugin ]');
|
|
8
|
+
|
|
9
|
+
function _class_call_check(instance, Constructor) {
|
|
10
|
+
if (!(instance instanceof Constructor)) {
|
|
11
|
+
throw new TypeError("Cannot call a class as a function");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function _defineProperties(target, props) {
|
|
15
|
+
for(var i = 0; i < props.length; i++){
|
|
16
|
+
var descriptor = props[i];
|
|
17
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
18
|
+
descriptor.configurable = true;
|
|
19
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
20
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
24
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
25
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
26
|
+
return Constructor;
|
|
27
|
+
}
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
var charMap = {
|
|
30
|
+
'<': '\\u003C',
|
|
31
|
+
'>': '\\u003E',
|
|
32
|
+
'/': '\\u002F',
|
|
33
|
+
'\\': '\\\\',
|
|
34
|
+
'\b': '\\b',
|
|
35
|
+
'\f': '\\f',
|
|
36
|
+
'\n': '\\n',
|
|
37
|
+
'\r': '\\r',
|
|
38
|
+
'\t': '\\t',
|
|
39
|
+
'\0': '\\0',
|
|
40
|
+
'\u2028': '\\u2028',
|
|
41
|
+
'\u2029': '\\u2029'
|
|
42
|
+
};
|
|
43
|
+
function escapeUnsafeChars(str) {
|
|
44
|
+
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, function(x) {
|
|
45
|
+
return charMap[x];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var RemoteEntryPlugin = /*#__PURE__*/ function() {
|
|
49
|
+
function RemoteEntryPlugin(options) {
|
|
50
|
+
_class_call_check(this, RemoteEntryPlugin);
|
|
51
|
+
this.name = 'VmokRemoteEntryPlugin';
|
|
52
|
+
this._options = options;
|
|
53
|
+
}
|
|
54
|
+
_create_class(RemoteEntryPlugin, [
|
|
55
|
+
{
|
|
56
|
+
key: "apply",
|
|
57
|
+
value: function apply(compiler) {
|
|
58
|
+
var _this__options = this._options, name = _this__options.name, getPublicPath = _this__options.getPublicPath;
|
|
59
|
+
if (!getPublicPath || !name) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
var containerManager = new managers.ContainerManager();
|
|
63
|
+
containerManager.init(this._options);
|
|
64
|
+
if (!containerManager.enable) {
|
|
65
|
+
logger.warn("Detect you don't set exposes, 'getPublicPath' will not have effect.");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
RemoteEntryPlugin.addPublicPathEntry(compiler, getPublicPath, name);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
], [
|
|
72
|
+
{
|
|
73
|
+
key: "addPublicPathEntry",
|
|
74
|
+
value: function addPublicPathEntry(compiler, getPublicPath, name) {
|
|
75
|
+
var code;
|
|
76
|
+
var sanitizedPublicPath = escapeUnsafeChars(getPublicPath);
|
|
77
|
+
if (!getPublicPath.startsWith('function')) {
|
|
78
|
+
code = "".concat(compiler.webpack.RuntimeGlobals.publicPath, " = new Function(").concat(JSON.stringify(sanitizedPublicPath), ")()");
|
|
79
|
+
} else {
|
|
80
|
+
code = "(".concat(sanitizedPublicPath, "())");
|
|
81
|
+
}
|
|
82
|
+
var base64Code = pBtoa(code);
|
|
83
|
+
var dataUrl = "data:text/javascript;base64,".concat(base64Code);
|
|
84
|
+
compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', function() {
|
|
85
|
+
new compiler.webpack.EntryPlugin(compiler.context, dataUrl, {
|
|
86
|
+
name: name
|
|
87
|
+
}).apply(compiler);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]);
|
|
92
|
+
return RemoteEntryPlugin;
|
|
93
|
+
}
|
|
94
|
+
();
|
|
95
|
+
|
|
96
|
+
exports.RemoteEntryPlugin = RemoteEntryPlugin;
|
|
97
|
+
//# sourceMappingURL=remote-entry-plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-entry-plugin.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/RemoteEntryPlugin";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/RemoteEntryPlugin";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import pBtoa from 'btoa';
|
|
2
|
+
import { ContainerManager } from '@module-federation/managers';
|
|
3
|
+
import { createLogger } from '@module-federation/sdk';
|
|
4
|
+
|
|
5
|
+
var logger = createLogger('[ Module Federation Rspack Plugin ]');
|
|
6
|
+
|
|
7
|
+
function _class_call_check(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for(var i = 0; i < props.length; i++){
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
return Constructor;
|
|
25
|
+
}
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
var charMap = {
|
|
28
|
+
'<': '\\u003C',
|
|
29
|
+
'>': '\\u003E',
|
|
30
|
+
'/': '\\u002F',
|
|
31
|
+
'\\': '\\\\',
|
|
32
|
+
'\b': '\\b',
|
|
33
|
+
'\f': '\\f',
|
|
34
|
+
'\n': '\\n',
|
|
35
|
+
'\r': '\\r',
|
|
36
|
+
'\t': '\\t',
|
|
37
|
+
'\0': '\\0',
|
|
38
|
+
'\u2028': '\\u2028',
|
|
39
|
+
'\u2029': '\\u2029'
|
|
40
|
+
};
|
|
41
|
+
function escapeUnsafeChars(str) {
|
|
42
|
+
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, function(x) {
|
|
43
|
+
return charMap[x];
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var RemoteEntryPlugin = /*#__PURE__*/ function() {
|
|
47
|
+
function RemoteEntryPlugin(options) {
|
|
48
|
+
_class_call_check(this, RemoteEntryPlugin);
|
|
49
|
+
this.name = 'VmokRemoteEntryPlugin';
|
|
50
|
+
this._options = options;
|
|
51
|
+
}
|
|
52
|
+
_create_class(RemoteEntryPlugin, [
|
|
53
|
+
{
|
|
54
|
+
key: "apply",
|
|
55
|
+
value: function apply(compiler) {
|
|
56
|
+
var _this__options = this._options, name = _this__options.name, getPublicPath = _this__options.getPublicPath;
|
|
57
|
+
if (!getPublicPath || !name) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var containerManager = new ContainerManager();
|
|
61
|
+
containerManager.init(this._options);
|
|
62
|
+
if (!containerManager.enable) {
|
|
63
|
+
logger.warn("Detect you don't set exposes, 'getPublicPath' will not have effect.");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
RemoteEntryPlugin.addPublicPathEntry(compiler, getPublicPath, name);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
], [
|
|
70
|
+
{
|
|
71
|
+
key: "addPublicPathEntry",
|
|
72
|
+
value: function addPublicPathEntry(compiler, getPublicPath, name) {
|
|
73
|
+
var code;
|
|
74
|
+
var sanitizedPublicPath = escapeUnsafeChars(getPublicPath);
|
|
75
|
+
if (!getPublicPath.startsWith('function')) {
|
|
76
|
+
code = "".concat(compiler.webpack.RuntimeGlobals.publicPath, " = new Function(").concat(JSON.stringify(sanitizedPublicPath), ")()");
|
|
77
|
+
} else {
|
|
78
|
+
code = "(".concat(sanitizedPublicPath, "())");
|
|
79
|
+
}
|
|
80
|
+
var base64Code = pBtoa(code);
|
|
81
|
+
var dataUrl = "data:text/javascript;base64,".concat(base64Code);
|
|
82
|
+
compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', function() {
|
|
83
|
+
new compiler.webpack.EntryPlugin(compiler.context, dataUrl, {
|
|
84
|
+
name: name
|
|
85
|
+
}).apply(compiler);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
return RemoteEntryPlugin;
|
|
91
|
+
}
|
|
92
|
+
();
|
|
93
|
+
|
|
94
|
+
export { RemoteEntryPlugin };
|
|
95
|
+
//# sourceMappingURL=remote-entry-plugin.esm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-entry-plugin.esm.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
import { RemoteEntryPlugin } from './RemoteEntryPlugin';
|
|
4
|
+
export declare const PLUGIN_NAME = "RspackModuleFederationPlugin";
|
|
5
|
+
export declare class ModuleFederationPlugin implements RspackPluginInstance {
|
|
6
|
+
readonly name = "RspackModuleFederationPlugin";
|
|
7
|
+
private _options;
|
|
8
|
+
private _statsPlugin?;
|
|
9
|
+
constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
|
|
10
|
+
private _patchBundlerConfig;
|
|
11
|
+
private _checkSingleton;
|
|
12
|
+
apply(compiler: Compiler): void;
|
|
13
|
+
private _patchChunkSplit;
|
|
14
|
+
get statsResourceInfo(): Partial<import("@module-federation/manifest").ResourceInfo> | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare const GetPublicPathPlugin: typeof RemoteEntryPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
export declare class RemoteEntryPlugin implements RspackPluginInstance {
|
|
4
|
+
readonly name = "VmokRemoteEntryPlugin";
|
|
5
|
+
_options: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
6
|
+
constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
|
|
7
|
+
static addPublicPathEntry(compiler: Compiler, getPublicPath: string, name: string): void;
|
|
8
|
+
apply(compiler: Compiler): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ModuleFederationPlugin, PLUGIN_NAME } from './ModuleFederationPlugin';
|
|
2
|
+
export declare const ContainerPlugin: typeof import("@rspack/core/dist/container/ContainerPlugin").ContainerPlugin;
|
|
3
|
+
export declare const ContainerReferencePlugin: typeof import("@rspack/core/dist/container/ContainerReferencePlugin").ContainerReferencePlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/rspack",
|
|
3
|
+
"version": "0.0.0-fix-lazy-comile-20250925082726",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Module Federation",
|
|
7
|
+
"Rspack"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/module-federation/core.git",
|
|
19
|
+
"directory": "packages/rspack"
|
|
20
|
+
},
|
|
21
|
+
"author": "hanric <hanric.zhang@gmail.com>",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.cjs.js",
|
|
24
|
+
"module": "./dist/index.esm.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"btoa": "1.2.1",
|
|
28
|
+
"@module-federation/bridge-react-webpack-plugin": "0.0.0-fix-lazy-comile-20250925082726",
|
|
29
|
+
"@module-federation/managers": "0.0.0-fix-lazy-comile-20250925082726",
|
|
30
|
+
"@module-federation/dts-plugin": "0.0.0-fix-lazy-comile-20250925082726",
|
|
31
|
+
"@module-federation/manifest": "0.0.0-fix-lazy-comile-20250925082726",
|
|
32
|
+
"@module-federation/runtime-tools": "0.0.0-fix-lazy-comile-20250925082726",
|
|
33
|
+
"@module-federation/inject-external-runtime-core-plugin": "0.0.0-fix-lazy-comile-20250925082726",
|
|
34
|
+
"@module-federation/sdk": "0.0.0-fix-lazy-comile-20250925082726"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@rspack/core": "^1.0.2"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"import": "./dist/index.esm.mjs",
|
|
43
|
+
"require": "./dist/index.cjs.js"
|
|
44
|
+
},
|
|
45
|
+
"./plugin": {
|
|
46
|
+
"types": "./dist/plugin.d.ts",
|
|
47
|
+
"import": "./dist/plugin.esm.mjs",
|
|
48
|
+
"require": "./dist/plugin.cjs.js"
|
|
49
|
+
},
|
|
50
|
+
"./remote-entry-plugin": {
|
|
51
|
+
"types": "./dist/remote-entry-plugin.d.ts",
|
|
52
|
+
"import": "./dist/remote-entry-plugin.esm.mjs",
|
|
53
|
+
"require": "./dist/remote-entry-plugin.cjs.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"typesVersions": {
|
|
57
|
+
"*": {
|
|
58
|
+
".": [
|
|
59
|
+
"./dist/index.d.ts"
|
|
60
|
+
],
|
|
61
|
+
"plugin": [
|
|
62
|
+
"./dist/plugin.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"remote-entry-plugin": [
|
|
65
|
+
"./dist/remote-entry-plugin.d.ts"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"typescript": "^4.9.0 || ^5.0.0",
|
|
71
|
+
"vue-tsc": ">=1.0.24",
|
|
72
|
+
"@rspack/core": ">=0.7"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"typescript": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"vue-tsc": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|