@module-federation/rspack 0.19.0 → 0.20.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.
@@ -1,297 +1,203 @@
1
- import { composeKeyWithSeparator } from '@module-federation/sdk';
1
+ import { composeKeyWithSeparator, bindLoggerToCompiler } from '@module-federation/sdk';
2
2
  import { StatsPlugin } from '@module-federation/manifest';
3
3
  import { utils, ContainerManager } from '@module-federation/managers';
4
4
  import { DtsPlugin } from '@module-federation/dts-plugin';
5
5
  import ReactBridgePlugin from '@module-federation/bridge-react-webpack-plugin';
6
6
  import path from 'node:path';
7
7
  import fs from 'node:fs';
8
- import { RemoteEntryPlugin } from './remote-entry-plugin.esm.mjs';
8
+ import { R as RemoteEntryPlugin, l as logger } from './RemoteEntryPlugin.esm.mjs';
9
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;
10
+ const RuntimeToolsPath = require.resolve('@module-federation/runtime-tools');
11
+ const PLUGIN_NAME = 'RspackModuleFederationPlugin';
12
+ class ModuleFederationPlugin {
13
+ constructor(options) {
14
+ this.name = PLUGIN_NAME;
15
+ this._options = options;
46
16
  }
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
- }));
17
+ _patchBundlerConfig(compiler) {
18
+ const { name, experiments } = this._options;
19
+ const definePluginOptions = {};
20
+ if (name) {
21
+ definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(composeKeyWithSeparator(name, utils.getBuildVersion()));
56
22
  }
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);
23
+ // Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
24
+ const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;
25
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] =
26
+ disableSnapshot;
27
+ // Determine ENV_TARGET: only if manually specified in experiments.optimization.target
28
+ if (experiments?.optimization &&
29
+ typeof experiments.optimization === 'object' &&
30
+ experiments.optimization !== null &&
31
+ 'target' in experiments.optimization) {
32
+ const manualTarget = experiments.optimization.target;
33
+ // Ensure the target is one of the expected values before setting
34
+ if (manualTarget === 'web' || manualTarget === 'node') {
35
+ definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);
36
+ }
37
+ }
38
+ // No inference for ENV_TARGET. If not manually set and valid, it's not defined.
39
+ new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
68
40
  }
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));
41
+ _checkSingleton(compiler) {
42
+ let count = 0;
43
+ compiler.options.plugins.forEach((p) => {
44
+ if (typeof p !== 'object' || !p) {
45
+ return;
46
+ }
47
+ if (p['name'] === this.name) {
48
+ count++;
49
+ if (count > 1) {
50
+ throw new Error(`Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`);
51
+ }
52
+ }
78
53
  });
79
54
  }
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
- }
55
+ apply(compiler) {
56
+ bindLoggerToCompiler(logger, compiler, PLUGIN_NAME);
57
+ const { _options: options } = this;
58
+ if (!options.name) {
59
+ throw new Error('[ ModuleFederationPlugin ]: name is required');
60
+ }
61
+ this._checkSingleton(compiler);
62
+ this._patchBundlerConfig(compiler);
63
+ const containerManager = new ContainerManager();
64
+ containerManager.init(options);
65
+ if (containerManager.enable) {
66
+ this._patchChunkSplit(compiler, options.name);
67
+ }
68
+ // must before ModuleFederationPlugin
69
+ new RemoteEntryPlugin(options).apply(compiler);
70
+ if (options.experiments?.provideExternalRuntime) {
71
+ if (options.exposes) {
72
+ throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
73
+ }
74
+ const runtimePlugins = options.runtimePlugins || [];
75
+ options.runtimePlugins = runtimePlugins.concat(require.resolve('@module-federation/inject-external-runtime-core-plugin'));
76
+ }
77
+ if (options.experiments?.externalRuntime === true) {
78
+ const Externals = compiler.webpack.ExternalsPlugin;
79
+ new Externals(compiler.options.externalsType || 'global', {
80
+ '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE',
81
+ }).apply(compiler);
82
+ }
83
+ options.implementation = options.implementation || RuntimeToolsPath;
84
+ let disableManifest = options.manifest === false;
85
+ let disableDts = options.dts === false;
86
+ if (!disableDts) {
87
+ const dtsPlugin = new DtsPlugin(options);
88
+ // @ts-ignore
89
+ dtsPlugin.apply(compiler);
90
+ dtsPlugin.addRuntimePlugins();
91
+ }
92
+ if (!disableManifest && options.exposes) {
93
+ try {
94
+ options.exposes = containerManager.containerPluginExposesOptions;
95
+ }
96
+ catch (err) {
97
+ if (err instanceof Error) {
98
+ err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;
115
99
  }
116
- // No inference for ENV_TARGET. If not manually set and valid, it's not defined.
117
- new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
100
+ logger.warn(err);
101
+ disableManifest = true;
118
102
  }
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;
103
+ }
104
+ new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
105
+ const runtimeESMPath = require.resolve('@module-federation/runtime/dist/index.esm.js', { paths: [options.implementation] });
106
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', () => {
107
+ compiler.options.resolve.alias = {
108
+ ...compiler.options.resolve.alias,
109
+ '@module-federation/runtime$': runtimeESMPath,
110
+ };
111
+ });
112
+ if (!disableManifest) {
113
+ this._statsPlugin = new StatsPlugin(options, {
114
+ pluginVersion: "0.20.0",
115
+ bundler: 'rspack',
116
+ });
117
+ // @ts-ignore
118
+ this._statsPlugin.apply(compiler);
119
+ }
120
+ // react bridge plugin
121
+ const nodeModulesPath = path.resolve(compiler.context, 'node_modules');
122
+ const reactPath = path.join(nodeModulesPath, '@module-federation/bridge-react');
123
+ // Check whether react exists
124
+ if (fs.existsSync(reactPath) &&
125
+ (!options?.bridge || !options.bridge.disableAlias)) {
126
+ new ReactBridgePlugin({
127
+ moduleFederationOptions: this._options,
128
+ }).apply(compiler);
129
+ }
130
+ }
131
+ _patchChunkSplit(compiler, name) {
132
+ const { splitChunks } = compiler.options.optimization;
133
+ const patchChunkSplit = (cacheGroup) => {
134
+ switch (typeof cacheGroup) {
135
+ case 'boolean':
136
+ case 'string':
137
+ case 'function':
138
+ break;
139
+ // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
140
+ case 'object': {
141
+ if (cacheGroup instanceof RegExp) {
142
+ break;
128
143
  }
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
- }
144
+ if (!cacheGroup.chunks) {
145
+ break;
134
146
  }
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.');
147
+ if (typeof cacheGroup.chunks === 'function') {
148
+ const prevChunks = cacheGroup.chunks;
149
+ cacheGroup.chunks = (chunk) => {
150
+ if (chunk.name &&
151
+ (chunk.name === name || chunk.name === name + '_partial')) {
152
+ return false;
153
+ }
154
+ return prevChunks(chunk);
155
+ };
156
+ break;
158
157
  }
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;
158
+ if (cacheGroup.chunks === 'all') {
159
+ cacheGroup.chunks = (chunk) => {
160
+ if (chunk.name &&
161
+ (chunk.name === name || chunk.name === name + '_partial')) {
162
+ return false;
163
+ }
164
+ return true;
165
+ };
166
+ break;
186
167
  }
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.19.0",
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;
168
+ if (cacheGroup.chunks === 'initial') {
169
+ cacheGroup.chunks = (chunk) => {
170
+ if (chunk.name &&
171
+ (chunk.name === name || chunk.name === name + '_partial')) {
172
+ return false;
266
173
  }
174
+ return chunk.isOnlyInitial();
175
+ };
176
+ break;
267
177
  }
268
- };
269
- if (!splitChunks) {
270
- return;
178
+ break;
271
179
  }
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
180
  }
181
+ };
182
+ if (!splitChunks) {
183
+ return;
290
184
  }
291
- ]);
292
- return ModuleFederationPlugin;
293
- }();
294
- var GetPublicPathPlugin = RemoteEntryPlugin;
185
+ // 修改 splitChunk.chunks
186
+ patchChunkSplit(splitChunks);
187
+ const { cacheGroups } = splitChunks;
188
+ if (!cacheGroups) {
189
+ return;
190
+ }
191
+ // 修改 splitChunk.cacheGroups[key].chunks
192
+ Object.keys(cacheGroups).forEach((cacheGroupKey) => {
193
+ patchChunkSplit(cacheGroups[cacheGroupKey]);
194
+ });
195
+ }
196
+ get statsResourceInfo() {
197
+ return this._statsPlugin?.resourceInfo;
198
+ }
199
+ }
200
+ const GetPublicPathPlugin = RemoteEntryPlugin;
295
201
 
296
202
  export { GetPublicPathPlugin, ModuleFederationPlugin, PLUGIN_NAME };
297
203
  //# sourceMappingURL=plugin.esm.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.esm.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,KAAI;4BAC5B,IACE,KAAK,CAAC,IAAI;AACV,iCAAC,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,UAAU,CAAC,EACzD;AACA,gCAAA,OAAO,KAAK;;AAEd,4BAAA,OAAO,KAAK,CAAC,aAAa,EAAE;AAC9B,yBAAC;wBACD;;oBAEF;;;AAKN,SAAC;QAED,IAAI,CAAC,WAAW,EAAE;YAChB;;;QAGF,eAAe,CAAC,WAAW,CAAC;AAE5B,QAAA,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW;QAEnC,IAAI,CAAC,WAAW,EAAE;YAChB;;;QAIF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,KAAI;AACjD,YAAA,eAAe,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AAC7C,SAAC,CAAC;;AAGJ,IAAA,IAAI,iBAAiB,GAAA;AACnB,QAAA,OAAO,IAAI,CAAC,YAAY,EAAE,YAAY;;AAEzC;AAEM,MAAM,mBAAmB,GAAG;;;;"}
@@ -1,97 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var pBtoa = require('btoa');
4
- var managers = require('@module-federation/managers');
5
- var sdk = require('@module-federation/sdk');
3
+ require('btoa');
4
+ require('@module-federation/managers');
5
+ var remoteEntryPlugin = require('./RemoteEntryPlugin.cjs.js');
6
6
 
7
- var logger = sdk.createLogger('[ Module Federation Rspack Plugin ]');
8
7
 
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
8
 
96
- exports.RemoteEntryPlugin = RemoteEntryPlugin;
9
+ exports.RemoteEntryPlugin = remoteEntryPlugin.RemoteEntryPlugin;
97
10
  //# sourceMappingURL=remote-entry-plugin.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-entry-plugin.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"remote-entry-plugin.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}