@module-federation/rspack 0.8.3 → 0.8.4

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 CHANGED
@@ -1,268 +1,18 @@
1
1
  'use strict';
2
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');
3
+ var plugin = require('./plugin.cjs.js');
10
4
  var core = require('@rspack/core');
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 ModuleFederationPlugin = /*#__PURE__*/ function() {
90
- function ModuleFederationPlugin(options) {
91
- _class_call_check(this, ModuleFederationPlugin);
92
- _define_property(this, "name", 'RspackModuleFederationPlugin');
93
- _define_property(this, "_options", void 0);
94
- _define_property(this, "_statsPlugin", void 0);
95
- this._options = options;
96
- }
97
- _create_class(ModuleFederationPlugin, [
98
- {
99
- key: "_patchBundlerConfig",
100
- value: function _patchBundlerConfig(compiler) {
101
- var name = this._options.name;
102
- if (name) {
103
- new compiler.webpack.DefinePlugin({
104
- FEDERATION_BUILD_IDENTIFIER: JSON.stringify(sdk.composeKeyWithSeparator(name, managers.utils.getBuildVersion()))
105
- }).apply(compiler);
106
- }
107
- }
108
- },
109
- {
110
- key: "_checkSingleton",
111
- value: function _checkSingleton(compiler) {
112
- var _this = this;
113
- var count = 0;
114
- compiler.options.plugins.forEach(function(p) {
115
- if (p.name === _this.name) {
116
- count++;
117
- if (count > 1) {
118
- throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
119
- }
120
- }
121
- });
122
- }
123
- },
124
- {
125
- key: "apply",
126
- value: function apply(compiler) {
127
- var _this = this, options = _this._options;
128
- if (!options.name) {
129
- throw new Error('[ ModuleFederationPlugin ]: name is required');
130
- }
131
- this._checkSingleton(compiler);
132
- this._patchBundlerConfig(compiler);
133
- var containerManager = new managers.ContainerManager();
134
- containerManager.init(options);
135
- if (containerManager.enable) {
136
- this._patchChunkSplit(compiler, options.name);
137
- }
138
- options.implementation = options.implementation || RuntimeToolsPath;
139
- var disableManifest = options.manifest === false;
140
- var disableDts = options.dts === false;
141
- if (!disableDts) {
142
- // @ts-ignore
143
- new dtsPlugin.DtsPlugin(options).apply(compiler);
144
- }
145
- if (!disableManifest && options.exposes) {
146
- try {
147
- options.exposes = containerManager.containerPluginExposesOptions;
148
- } catch (err) {
149
- if (_instanceof(err, Error)) {
150
- err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
151
- }
152
- console.warn(err);
153
- disableManifest = true;
154
- }
155
- }
156
- new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
157
- var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.mjs', {
158
- paths: [
159
- options.implementation
160
- ]
161
- });
162
- compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
163
- compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
164
- '@module-federation/runtime$': runtimeESMPath
165
- });
166
- });
167
- if (!disableManifest) {
168
- this._statsPlugin = new manifest.StatsPlugin(options, {
169
- pluginVersion: "0.8.3",
170
- bundler: 'rspack'
171
- });
172
- // @ts-ignore
173
- this._statsPlugin.apply(compiler);
174
- }
175
- // react bridge plugin
176
- var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
177
- var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
178
- // Check whether react exists
179
- if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
180
- new ReactBridgePlugin({
181
- moduleFederationOptions: this._options
182
- }).apply(compiler);
183
- }
184
- }
185
- },
186
- {
187
- key: "_patchChunkSplit",
188
- value: function _patchChunkSplit(compiler, name) {
189
- var splitChunks = compiler.options.optimization.splitChunks;
190
- var patchChunkSplit = function(cacheGroup) {
191
- switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
192
- case 'boolean':
193
- case 'string':
194
- case 'function':
195
- break;
196
- // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
197
- case 'object':
198
- {
199
- if (_instanceof(cacheGroup, RegExp)) {
200
- break;
201
- }
202
- if (!cacheGroup.chunks) {
203
- break;
204
- }
205
- if (typeof cacheGroup.chunks === 'function') {
206
- var prevChunks = cacheGroup.chunks;
207
- cacheGroup.chunks = function(chunk) {
208
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
209
- return false;
210
- }
211
- return prevChunks(chunk);
212
- };
213
- break;
214
- }
215
- if (cacheGroup.chunks === 'all') {
216
- cacheGroup.chunks = function(chunk) {
217
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
218
- return false;
219
- }
220
- return true;
221
- };
222
- break;
223
- }
224
- if (cacheGroup.chunks === 'initial') {
225
- cacheGroup.chunks = function(chunk) {
226
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
227
- return false;
228
- }
229
- return chunk.isOnlyInitial();
230
- };
231
- break;
232
- }
233
- break;
234
- }
235
- }
236
- };
237
- if (!splitChunks) {
238
- return;
239
- }
240
- // 修改 splitChunk.chunks
241
- patchChunkSplit(splitChunks);
242
- var cacheGroups = splitChunks.cacheGroups;
243
- if (!cacheGroups) {
244
- return;
245
- }
246
- // 修改 splitChunk.cacheGroups[key].chunks
247
- Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
248
- patchChunkSplit(cacheGroups[cacheGroupKey]);
249
- });
250
- }
251
- },
252
- {
253
- key: "statsResourceInfo",
254
- get: function get() {
255
- var _this__statsPlugin;
256
- return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
257
- }
258
- }
259
- ]);
260
- return ModuleFederationPlugin;
261
- }();
5
+ require('@module-federation/sdk');
6
+ require('@module-federation/manifest');
7
+ require('@module-federation/managers');
8
+ require('@module-federation/dts-plugin');
9
+ require('@module-federation/bridge-react-webpack-plugin');
10
+ require('node:path');
11
+ require('node:fs');
262
12
 
263
13
  var ContainerPlugin = core.container.ContainerPlugin;
264
14
  var ContainerReferencePlugin = core.container.ContainerReferencePlugin;
265
15
 
16
+ exports.ModuleFederationPlugin = plugin.ModuleFederationPlugin;
266
17
  exports.ContainerPlugin = ContainerPlugin;
267
18
  exports.ContainerReferencePlugin = ContainerReferencePlugin;
268
- exports.ModuleFederationPlugin = ModuleFederationPlugin;
package/dist/index.esm.js CHANGED
@@ -1,264 +1,14 @@
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';
1
+ export { ModuleFederationPlugin } from './plugin.esm.js';
8
2
  import { container } from '@rspack/core';
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 ModuleFederationPlugin = /*#__PURE__*/ function() {
88
- function ModuleFederationPlugin(options) {
89
- _class_call_check(this, ModuleFederationPlugin);
90
- _define_property(this, "name", 'RspackModuleFederationPlugin');
91
- _define_property(this, "_options", void 0);
92
- _define_property(this, "_statsPlugin", void 0);
93
- this._options = options;
94
- }
95
- _create_class(ModuleFederationPlugin, [
96
- {
97
- key: "_patchBundlerConfig",
98
- value: function _patchBundlerConfig(compiler) {
99
- var name = this._options.name;
100
- if (name) {
101
- new compiler.webpack.DefinePlugin({
102
- FEDERATION_BUILD_IDENTIFIER: JSON.stringify(composeKeyWithSeparator(name, utils.getBuildVersion()))
103
- }).apply(compiler);
104
- }
105
- }
106
- },
107
- {
108
- key: "_checkSingleton",
109
- value: function _checkSingleton(compiler) {
110
- var _this = this;
111
- var count = 0;
112
- compiler.options.plugins.forEach(function(p) {
113
- if (p.name === _this.name) {
114
- count++;
115
- if (count > 1) {
116
- throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
117
- }
118
- }
119
- });
120
- }
121
- },
122
- {
123
- key: "apply",
124
- value: function apply(compiler) {
125
- var _this = this, options = _this._options;
126
- if (!options.name) {
127
- throw new Error('[ ModuleFederationPlugin ]: name is required');
128
- }
129
- this._checkSingleton(compiler);
130
- this._patchBundlerConfig(compiler);
131
- var containerManager = new ContainerManager();
132
- containerManager.init(options);
133
- if (containerManager.enable) {
134
- this._patchChunkSplit(compiler, options.name);
135
- }
136
- options.implementation = options.implementation || RuntimeToolsPath;
137
- var disableManifest = options.manifest === false;
138
- var disableDts = options.dts === false;
139
- if (!disableDts) {
140
- // @ts-ignore
141
- new DtsPlugin(options).apply(compiler);
142
- }
143
- if (!disableManifest && options.exposes) {
144
- try {
145
- options.exposes = containerManager.containerPluginExposesOptions;
146
- } catch (err) {
147
- if (_instanceof(err, Error)) {
148
- err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
149
- }
150
- console.warn(err);
151
- disableManifest = true;
152
- }
153
- }
154
- new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
155
- var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.mjs', {
156
- paths: [
157
- options.implementation
158
- ]
159
- });
160
- compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
161
- compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
162
- '@module-federation/runtime$': runtimeESMPath
163
- });
164
- });
165
- if (!disableManifest) {
166
- this._statsPlugin = new StatsPlugin(options, {
167
- pluginVersion: "0.8.3",
168
- bundler: 'rspack'
169
- });
170
- // @ts-ignore
171
- this._statsPlugin.apply(compiler);
172
- }
173
- // react bridge plugin
174
- var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
175
- var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
176
- // Check whether react exists
177
- if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
178
- new ReactBridgePlugin({
179
- moduleFederationOptions: this._options
180
- }).apply(compiler);
181
- }
182
- }
183
- },
184
- {
185
- key: "_patchChunkSplit",
186
- value: function _patchChunkSplit(compiler, name) {
187
- var splitChunks = compiler.options.optimization.splitChunks;
188
- var patchChunkSplit = function(cacheGroup) {
189
- switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
190
- case 'boolean':
191
- case 'string':
192
- case 'function':
193
- break;
194
- // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
195
- case 'object':
196
- {
197
- if (_instanceof(cacheGroup, RegExp)) {
198
- break;
199
- }
200
- if (!cacheGroup.chunks) {
201
- break;
202
- }
203
- if (typeof cacheGroup.chunks === 'function') {
204
- var prevChunks = cacheGroup.chunks;
205
- cacheGroup.chunks = function(chunk) {
206
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
207
- return false;
208
- }
209
- return prevChunks(chunk);
210
- };
211
- break;
212
- }
213
- if (cacheGroup.chunks === 'all') {
214
- cacheGroup.chunks = function(chunk) {
215
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
216
- return false;
217
- }
218
- return true;
219
- };
220
- break;
221
- }
222
- if (cacheGroup.chunks === 'initial') {
223
- cacheGroup.chunks = function(chunk) {
224
- if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
225
- return false;
226
- }
227
- return chunk.isOnlyInitial();
228
- };
229
- break;
230
- }
231
- break;
232
- }
233
- }
234
- };
235
- if (!splitChunks) {
236
- return;
237
- }
238
- // 修改 splitChunk.chunks
239
- patchChunkSplit(splitChunks);
240
- var cacheGroups = splitChunks.cacheGroups;
241
- if (!cacheGroups) {
242
- return;
243
- }
244
- // 修改 splitChunk.cacheGroups[key].chunks
245
- Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
246
- patchChunkSplit(cacheGroups[cacheGroupKey]);
247
- });
248
- }
249
- },
250
- {
251
- key: "statsResourceInfo",
252
- get: function get() {
253
- var _this__statsPlugin;
254
- return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
255
- }
256
- }
257
- ]);
258
- return ModuleFederationPlugin;
259
- }();
3
+ import '@module-federation/sdk';
4
+ import '@module-federation/manifest';
5
+ import '@module-federation/managers';
6
+ import '@module-federation/dts-plugin';
7
+ import '@module-federation/bridge-react-webpack-plugin';
8
+ import 'node:path';
9
+ import 'node:fs';
260
10
 
261
11
  var ContainerPlugin = container.ContainerPlugin;
262
12
  var ContainerReferencePlugin = container.ContainerReferencePlugin;
263
13
 
264
- export { ContainerPlugin, ContainerReferencePlugin, ModuleFederationPlugin };
14
+ export { ContainerPlugin, ContainerReferencePlugin };
@@ -0,0 +1 @@
1
+ export * from "./src/ModuleFederationPlugin";
@@ -0,0 +1,262 @@
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
+
11
+ function _class_call_check(instance, Constructor) {
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ }
16
+ function _defineProperties(target, props) {
17
+ for(var i = 0; i < props.length; i++){
18
+ var descriptor = props[i];
19
+ descriptor.enumerable = descriptor.enumerable || false;
20
+ descriptor.configurable = true;
21
+ if ("value" in descriptor) descriptor.writable = true;
22
+ Object.defineProperty(target, descriptor.key, descriptor);
23
+ }
24
+ }
25
+ function _create_class(Constructor, protoProps, staticProps) {
26
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
27
+ return Constructor;
28
+ }
29
+ function _define_property(obj, key, value) {
30
+ if (key in obj) {
31
+ Object.defineProperty(obj, key, {
32
+ value: value,
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true
36
+ });
37
+ } else {
38
+ obj[key] = value;
39
+ }
40
+ return obj;
41
+ }
42
+ function _instanceof(left, right) {
43
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
44
+ return !!right[Symbol.hasInstance](left);
45
+ } else {
46
+ return left instanceof right;
47
+ }
48
+ }
49
+ function _object_spread(target) {
50
+ for(var i = 1; i < arguments.length; i++){
51
+ var source = arguments[i] != null ? arguments[i] : {};
52
+ var ownKeys = Object.keys(source);
53
+ if (typeof Object.getOwnPropertySymbols === "function") {
54
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
+ }));
57
+ }
58
+ ownKeys.forEach(function(key) {
59
+ _define_property(target, key, source[key]);
60
+ });
61
+ }
62
+ return target;
63
+ }
64
+ function ownKeys(object, enumerableOnly) {
65
+ var keys = Object.keys(object);
66
+ if (Object.getOwnPropertySymbols) {
67
+ var symbols = Object.getOwnPropertySymbols(object);
68
+ keys.push.apply(keys, symbols);
69
+ }
70
+ return keys;
71
+ }
72
+ function _object_spread_props(target, source) {
73
+ source = source != null ? source : {};
74
+ if (Object.getOwnPropertyDescriptors) {
75
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
76
+ } else {
77
+ ownKeys(Object(source)).forEach(function(key) {
78
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
79
+ });
80
+ }
81
+ return target;
82
+ }
83
+ function _type_of(obj) {
84
+ "@swc/helpers - typeof";
85
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
86
+ }
87
+ var RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
88
+ var ModuleFederationPlugin = /*#__PURE__*/ function() {
89
+ function ModuleFederationPlugin(options) {
90
+ _class_call_check(this, ModuleFederationPlugin);
91
+ _define_property(this, "name", 'RspackModuleFederationPlugin');
92
+ _define_property(this, "_options", void 0);
93
+ _define_property(this, "_statsPlugin", void 0);
94
+ this._options = options;
95
+ }
96
+ _create_class(ModuleFederationPlugin, [
97
+ {
98
+ key: "_patchBundlerConfig",
99
+ value: function _patchBundlerConfig(compiler) {
100
+ var name = this._options.name;
101
+ if (name) {
102
+ new compiler.webpack.DefinePlugin({
103
+ FEDERATION_BUILD_IDENTIFIER: JSON.stringify(sdk.composeKeyWithSeparator(name, managers.utils.getBuildVersion()))
104
+ }).apply(compiler);
105
+ }
106
+ }
107
+ },
108
+ {
109
+ key: "_checkSingleton",
110
+ value: function _checkSingleton(compiler) {
111
+ var _this = this;
112
+ var count = 0;
113
+ compiler.options.plugins.forEach(function(p) {
114
+ if (p.name === _this.name) {
115
+ count++;
116
+ if (count > 1) {
117
+ throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
118
+ }
119
+ }
120
+ });
121
+ }
122
+ },
123
+ {
124
+ key: "apply",
125
+ value: function apply(compiler) {
126
+ var _this = this, options = _this._options;
127
+ if (!options.name) {
128
+ throw new Error('[ ModuleFederationPlugin ]: name is required');
129
+ }
130
+ this._checkSingleton(compiler);
131
+ this._patchBundlerConfig(compiler);
132
+ var containerManager = new managers.ContainerManager();
133
+ containerManager.init(options);
134
+ if (containerManager.enable) {
135
+ this._patchChunkSplit(compiler, options.name);
136
+ }
137
+ options.implementation = options.implementation || RuntimeToolsPath;
138
+ var disableManifest = options.manifest === false;
139
+ var disableDts = options.dts === false;
140
+ if (!disableDts) {
141
+ // @ts-ignore
142
+ new dtsPlugin.DtsPlugin(options).apply(compiler);
143
+ }
144
+ if (!disableManifest && options.exposes) {
145
+ try {
146
+ options.exposes = containerManager.containerPluginExposesOptions;
147
+ } catch (err) {
148
+ if (_instanceof(err, Error)) {
149
+ err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
150
+ }
151
+ console.warn(err);
152
+ disableManifest = true;
153
+ }
154
+ }
155
+ new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
156
+ var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.mjs', {
157
+ paths: [
158
+ options.implementation
159
+ ]
160
+ });
161
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
162
+ compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
163
+ '@module-federation/runtime$': runtimeESMPath
164
+ });
165
+ });
166
+ if (!disableManifest) {
167
+ this._statsPlugin = new manifest.StatsPlugin(options, {
168
+ pluginVersion: "0.8.4",
169
+ bundler: 'rspack'
170
+ });
171
+ // @ts-ignore
172
+ this._statsPlugin.apply(compiler);
173
+ }
174
+ // react bridge plugin
175
+ var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
176
+ var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
177
+ // Check whether react exists
178
+ if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
179
+ new ReactBridgePlugin({
180
+ moduleFederationOptions: this._options
181
+ }).apply(compiler);
182
+ }
183
+ }
184
+ },
185
+ {
186
+ key: "_patchChunkSplit",
187
+ value: function _patchChunkSplit(compiler, name) {
188
+ var splitChunks = compiler.options.optimization.splitChunks;
189
+ var patchChunkSplit = function(cacheGroup) {
190
+ switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
191
+ case 'boolean':
192
+ case 'string':
193
+ case 'function':
194
+ break;
195
+ // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
196
+ case 'object':
197
+ {
198
+ if (_instanceof(cacheGroup, RegExp)) {
199
+ break;
200
+ }
201
+ if (!cacheGroup.chunks) {
202
+ break;
203
+ }
204
+ if (typeof cacheGroup.chunks === 'function') {
205
+ var prevChunks = cacheGroup.chunks;
206
+ cacheGroup.chunks = function(chunk) {
207
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
208
+ return false;
209
+ }
210
+ return prevChunks(chunk);
211
+ };
212
+ break;
213
+ }
214
+ if (cacheGroup.chunks === 'all') {
215
+ cacheGroup.chunks = function(chunk) {
216
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
217
+ return false;
218
+ }
219
+ return true;
220
+ };
221
+ break;
222
+ }
223
+ if (cacheGroup.chunks === 'initial') {
224
+ cacheGroup.chunks = function(chunk) {
225
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
226
+ return false;
227
+ }
228
+ return chunk.isOnlyInitial();
229
+ };
230
+ break;
231
+ }
232
+ break;
233
+ }
234
+ }
235
+ };
236
+ if (!splitChunks) {
237
+ return;
238
+ }
239
+ // 修改 splitChunk.chunks
240
+ patchChunkSplit(splitChunks);
241
+ var cacheGroups = splitChunks.cacheGroups;
242
+ if (!cacheGroups) {
243
+ return;
244
+ }
245
+ // 修改 splitChunk.cacheGroups[key].chunks
246
+ Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
247
+ patchChunkSplit(cacheGroups[cacheGroupKey]);
248
+ });
249
+ }
250
+ },
251
+ {
252
+ key: "statsResourceInfo",
253
+ get: function get() {
254
+ var _this__statsPlugin;
255
+ return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
256
+ }
257
+ }
258
+ ]);
259
+ return ModuleFederationPlugin;
260
+ }();
261
+
262
+ exports.ModuleFederationPlugin = ModuleFederationPlugin;
@@ -0,0 +1 @@
1
+ export * from "./src/ModuleFederationPlugin";
@@ -0,0 +1,260 @@
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
+
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
+ return Constructor;
26
+ }
27
+ function _define_property(obj, key, value) {
28
+ if (key in obj) {
29
+ Object.defineProperty(obj, key, {
30
+ value: value,
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true
34
+ });
35
+ } else {
36
+ obj[key] = value;
37
+ }
38
+ return obj;
39
+ }
40
+ function _instanceof(left, right) {
41
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
42
+ return !!right[Symbol.hasInstance](left);
43
+ } else {
44
+ return left instanceof right;
45
+ }
46
+ }
47
+ function _object_spread(target) {
48
+ for(var i = 1; i < arguments.length; i++){
49
+ var source = arguments[i] != null ? arguments[i] : {};
50
+ var ownKeys = Object.keys(source);
51
+ if (typeof Object.getOwnPropertySymbols === "function") {
52
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
53
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
54
+ }));
55
+ }
56
+ ownKeys.forEach(function(key) {
57
+ _define_property(target, key, source[key]);
58
+ });
59
+ }
60
+ return target;
61
+ }
62
+ function ownKeys(object, enumerableOnly) {
63
+ var keys = Object.keys(object);
64
+ if (Object.getOwnPropertySymbols) {
65
+ var symbols = Object.getOwnPropertySymbols(object);
66
+ keys.push.apply(keys, symbols);
67
+ }
68
+ return keys;
69
+ }
70
+ function _object_spread_props(target, source) {
71
+ source = source != null ? source : {};
72
+ if (Object.getOwnPropertyDescriptors) {
73
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
74
+ } else {
75
+ ownKeys(Object(source)).forEach(function(key) {
76
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
77
+ });
78
+ }
79
+ return target;
80
+ }
81
+ function _type_of(obj) {
82
+ "@swc/helpers - typeof";
83
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
84
+ }
85
+ var RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
86
+ var ModuleFederationPlugin = /*#__PURE__*/ function() {
87
+ function ModuleFederationPlugin(options) {
88
+ _class_call_check(this, ModuleFederationPlugin);
89
+ _define_property(this, "name", 'RspackModuleFederationPlugin');
90
+ _define_property(this, "_options", void 0);
91
+ _define_property(this, "_statsPlugin", void 0);
92
+ this._options = options;
93
+ }
94
+ _create_class(ModuleFederationPlugin, [
95
+ {
96
+ key: "_patchBundlerConfig",
97
+ value: function _patchBundlerConfig(compiler) {
98
+ var name = this._options.name;
99
+ if (name) {
100
+ new compiler.webpack.DefinePlugin({
101
+ FEDERATION_BUILD_IDENTIFIER: JSON.stringify(composeKeyWithSeparator(name, utils.getBuildVersion()))
102
+ }).apply(compiler);
103
+ }
104
+ }
105
+ },
106
+ {
107
+ key: "_checkSingleton",
108
+ value: function _checkSingleton(compiler) {
109
+ var _this = this;
110
+ var count = 0;
111
+ compiler.options.plugins.forEach(function(p) {
112
+ if (p.name === _this.name) {
113
+ count++;
114
+ if (count > 1) {
115
+ throw new Error("Detect duplicate register ".concat(_this.name, ",please ensure ").concat(_this.name, " is singleton!"));
116
+ }
117
+ }
118
+ });
119
+ }
120
+ },
121
+ {
122
+ key: "apply",
123
+ value: function apply(compiler) {
124
+ var _this = this, options = _this._options;
125
+ if (!options.name) {
126
+ throw new Error('[ ModuleFederationPlugin ]: name is required');
127
+ }
128
+ this._checkSingleton(compiler);
129
+ this._patchBundlerConfig(compiler);
130
+ var containerManager = new ContainerManager();
131
+ containerManager.init(options);
132
+ if (containerManager.enable) {
133
+ this._patchChunkSplit(compiler, options.name);
134
+ }
135
+ options.implementation = options.implementation || RuntimeToolsPath;
136
+ var disableManifest = options.manifest === false;
137
+ var disableDts = options.dts === false;
138
+ if (!disableDts) {
139
+ // @ts-ignore
140
+ new DtsPlugin(options).apply(compiler);
141
+ }
142
+ if (!disableManifest && options.exposes) {
143
+ try {
144
+ options.exposes = containerManager.containerPluginExposesOptions;
145
+ } catch (err) {
146
+ if (_instanceof(err, Error)) {
147
+ err.message = "[ ModuleFederationPlugin ]: Manifest will not generate, because: ".concat(err.message);
148
+ }
149
+ console.warn(err);
150
+ disableManifest = true;
151
+ }
152
+ }
153
+ new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
154
+ var runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.mjs', {
155
+ paths: [
156
+ options.implementation
157
+ ]
158
+ });
159
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', function() {
160
+ compiler.options.resolve.alias = _object_spread_props(_object_spread({}, compiler.options.resolve.alias), {
161
+ '@module-federation/runtime$': runtimeESMPath
162
+ });
163
+ });
164
+ if (!disableManifest) {
165
+ this._statsPlugin = new StatsPlugin(options, {
166
+ pluginVersion: "0.8.4",
167
+ bundler: 'rspack'
168
+ });
169
+ // @ts-ignore
170
+ this._statsPlugin.apply(compiler);
171
+ }
172
+ // react bridge plugin
173
+ var nodeModulesPath = path.resolve(compiler.context, 'node_modules');
174
+ var reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
175
+ // Check whether react exists
176
+ if (fs.existsSync(reactPath) && (!(options === null || options === void 0 ? void 0 : options.bridge) || !options.bridge.disableAlias)) {
177
+ new ReactBridgePlugin({
178
+ moduleFederationOptions: this._options
179
+ }).apply(compiler);
180
+ }
181
+ }
182
+ },
183
+ {
184
+ key: "_patchChunkSplit",
185
+ value: function _patchChunkSplit(compiler, name) {
186
+ var splitChunks = compiler.options.optimization.splitChunks;
187
+ var patchChunkSplit = function(cacheGroup) {
188
+ switch(typeof cacheGroup === "undefined" ? "undefined" : _type_of(cacheGroup)){
189
+ case 'boolean':
190
+ case 'string':
191
+ case 'function':
192
+ break;
193
+ // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
194
+ case 'object':
195
+ {
196
+ if (_instanceof(cacheGroup, RegExp)) {
197
+ break;
198
+ }
199
+ if (!cacheGroup.chunks) {
200
+ break;
201
+ }
202
+ if (typeof cacheGroup.chunks === 'function') {
203
+ var prevChunks = cacheGroup.chunks;
204
+ cacheGroup.chunks = function(chunk) {
205
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
206
+ return false;
207
+ }
208
+ return prevChunks(chunk);
209
+ };
210
+ break;
211
+ }
212
+ if (cacheGroup.chunks === 'all') {
213
+ cacheGroup.chunks = function(chunk) {
214
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
215
+ return false;
216
+ }
217
+ return true;
218
+ };
219
+ break;
220
+ }
221
+ if (cacheGroup.chunks === 'initial') {
222
+ cacheGroup.chunks = function(chunk) {
223
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
224
+ return false;
225
+ }
226
+ return chunk.isOnlyInitial();
227
+ };
228
+ break;
229
+ }
230
+ break;
231
+ }
232
+ }
233
+ };
234
+ if (!splitChunks) {
235
+ return;
236
+ }
237
+ // 修改 splitChunk.chunks
238
+ patchChunkSplit(splitChunks);
239
+ var cacheGroups = splitChunks.cacheGroups;
240
+ if (!cacheGroups) {
241
+ return;
242
+ }
243
+ // 修改 splitChunk.cacheGroups[key].chunks
244
+ Object.keys(cacheGroups).forEach(function(cacheGroupKey) {
245
+ patchChunkSplit(cacheGroups[cacheGroupKey]);
246
+ });
247
+ }
248
+ },
249
+ {
250
+ key: "statsResourceInfo",
251
+ get: function get() {
252
+ var _this__statsPlugin;
253
+ return (_this__statsPlugin = this._statsPlugin) === null || _this__statsPlugin === void 0 ? void 0 : _this__statsPlugin.resourceInfo;
254
+ }
255
+ }
256
+ ]);
257
+ return ModuleFederationPlugin;
258
+ }();
259
+
260
+ export { ModuleFederationPlugin };
@@ -1,4 +1,4 @@
1
- import { Compiler, RspackPluginInstance } from '@rspack/core';
1
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
2
  import { moduleFederationPlugin } from '@module-federation/sdk';
3
3
  export declare class ModuleFederationPlugin implements RspackPluginInstance {
4
4
  readonly name = "RspackModuleFederationPlugin";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/rspack",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "Module Federation",
@@ -24,12 +24,12 @@
24
24
  "module": "./dist/index.esm.js",
25
25
  "types": "./dist/index.cjs.d.ts",
26
26
  "dependencies": {
27
- "@module-federation/bridge-react-webpack-plugin": "0.8.3",
28
- "@module-federation/dts-plugin": "0.8.3",
29
- "@module-federation/managers": "0.8.3",
30
- "@module-federation/manifest": "0.8.3",
31
- "@module-federation/runtime-tools": "0.8.3",
32
- "@module-federation/sdk": "0.8.3"
27
+ "@module-federation/bridge-react-webpack-plugin": "0.8.4",
28
+ "@module-federation/dts-plugin": "0.8.4",
29
+ "@module-federation/managers": "0.8.4",
30
+ "@module-federation/manifest": "0.8.4",
31
+ "@module-federation/runtime-tools": "0.8.4",
32
+ "@module-federation/sdk": "0.8.4"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@rspack/core": "^1.0.2"
@@ -39,12 +39,20 @@
39
39
  "import": "./dist/index.esm.js",
40
40
  "require": "./dist/index.cjs.js",
41
41
  "types": "./dist/index.cjs.d.ts"
42
+ },
43
+ "./plugin": {
44
+ "types": "./dist/plugin.cjs.d.ts",
45
+ "import": "./dist/plugin.esm.mjs",
46
+ "require": "./dist/plugin.cjs.js"
42
47
  }
43
48
  },
44
49
  "typesVersions": {
45
50
  "*": {
46
51
  ".": [
47
52
  "./dist/index.cjs.d.ts"
53
+ ],
54
+ "plugin": [
55
+ "./dist/plugin.cjs.d.ts"
48
56
  ]
49
57
  }
50
58
  },