@module-federation/vite 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -54
- package/lib/index.cjs +134 -150
- package/lib/index.esm.js +134 -150
- package/lib/index.modern.js +148 -164
- package/lib/index.umd.js +134 -150
- package/lib/plugins/pluginDevProxyModuleTopLevelAwait.d.ts +1 -1
- package/lib/plugins/pluginModuleParseEnd.d.ts +1 -1
- package/lib/plugins/pluginProxyRemotes.d.ts +2 -2
- package/lib/utils/__tests__/normalizeModuleFederationOption.test.d.ts +1 -0
- package/lib/utils/logUtils.d.ts +1 -0
- package/lib/utils/normalizeModuleFederationOptions.d.ts +39 -7
- package/lib/virtualModules/index.d.ts +5 -4
- package/lib/virtualModules/virtualExposes.d.ts +2 -0
- package/lib/virtualModules/virtualRuntimeInitStatus.d.ts +1 -1
- package/lib/virtualModules/virtualShared_preBuild.d.ts +5 -5
- package/package.json +11 -4
package/lib/index.cjs
CHANGED
|
@@ -34,13 +34,13 @@ var addEntry = function addEntry(_ref) {
|
|
|
34
34
|
var entryName = _ref.entryName,
|
|
35
35
|
entryPath = _ref.entryPath,
|
|
36
36
|
fileName = _ref.fileName;
|
|
37
|
-
var devEntryPath = entryPath.startsWith(
|
|
37
|
+
var devEntryPath = entryPath.startsWith('virtual:mf') ? '/@id/' + entryPath : entryPath;
|
|
38
38
|
var entryFiles = [];
|
|
39
39
|
var htmlFilePath;
|
|
40
40
|
var _command;
|
|
41
41
|
return [{
|
|
42
42
|
name: 'add-entry',
|
|
43
|
-
apply:
|
|
43
|
+
apply: 'serve',
|
|
44
44
|
config: function config(_config, _ref2) {
|
|
45
45
|
var command = _ref2.command;
|
|
46
46
|
_command = command;
|
|
@@ -66,8 +66,8 @@ var addEntry = function addEntry(_ref) {
|
|
|
66
66
|
return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
|
|
67
67
|
}
|
|
68
68
|
}, {
|
|
69
|
-
name:
|
|
70
|
-
enforce:
|
|
69
|
+
name: 'add-entry',
|
|
70
|
+
enforce: 'post',
|
|
71
71
|
configResolved: function configResolved(config) {
|
|
72
72
|
var inputOptions = config.build.rollupOptions.input;
|
|
73
73
|
if (!inputOptions) {
|
|
@@ -84,8 +84,8 @@ var addEntry = function addEntry(_ref) {
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
buildStart: function buildStart() {
|
|
87
|
-
if (_command ===
|
|
88
|
-
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes(
|
|
87
|
+
if (_command === 'serve') return;
|
|
88
|
+
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes('[hash');
|
|
89
89
|
var emitFileOptions = {
|
|
90
90
|
name: entryName,
|
|
91
91
|
type: 'chunk',
|
|
@@ -122,10 +122,10 @@ var addEntry = function addEntry(_ref) {
|
|
|
122
122
|
function PluginDevProxyModuleTopLevelAwait() {
|
|
123
123
|
var filterFunction = pluginutils.createFilter();
|
|
124
124
|
return {
|
|
125
|
-
name:
|
|
126
|
-
apply:
|
|
125
|
+
name: 'dev-proxy-module-top-level-await',
|
|
126
|
+
apply: 'serve',
|
|
127
127
|
transform: function transform(code, id) {
|
|
128
|
-
if (!code.includes(
|
|
128
|
+
if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
|
|
129
129
|
return null;
|
|
130
130
|
}
|
|
131
131
|
if (!filterFunction(id)) return null;
|
|
@@ -209,6 +209,15 @@ function _createForOfIteratorHelperLoose(r, e) {
|
|
|
209
209
|
}
|
|
210
210
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
211
211
|
}
|
|
212
|
+
function _extends() {
|
|
213
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
214
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
215
|
+
var t = arguments[e];
|
|
216
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
217
|
+
}
|
|
218
|
+
return n;
|
|
219
|
+
}, _extends.apply(null, arguments);
|
|
220
|
+
}
|
|
212
221
|
function _unsupportedIterableToArray(r, a) {
|
|
213
222
|
if (r) {
|
|
214
223
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -217,6 +226,12 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
217
226
|
}
|
|
218
227
|
}
|
|
219
228
|
|
|
229
|
+
var warn = function warn(message) {
|
|
230
|
+
return message.split('\n').forEach(function (msg) {
|
|
231
|
+
return console.warn('\x1b[33m%s\x1b[0m', msg);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
220
235
|
function normalizeExposesItem(key, item) {
|
|
221
236
|
var importPath = '';
|
|
222
237
|
if (typeof item === 'string') {
|
|
@@ -290,7 +305,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
290
305
|
from: '',
|
|
291
306
|
shareConfig: {
|
|
292
307
|
singleton: false,
|
|
293
|
-
requiredVersion: "^" + version
|
|
308
|
+
requiredVersion: version ? "^" + version : '*'
|
|
294
309
|
}
|
|
295
310
|
};
|
|
296
311
|
}
|
|
@@ -301,7 +316,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
301
316
|
scope: shareItem.shareScope || 'default',
|
|
302
317
|
shareConfig: {
|
|
303
318
|
singleton: shareItem.singleton || false,
|
|
304
|
-
requiredVersion: shareItem.requiredVersion || "^" + version
|
|
319
|
+
requiredVersion: shareItem.requiredVersion || (version ? "^" + version : '*'),
|
|
305
320
|
strictVersion: !!shareItem.strictVersion
|
|
306
321
|
}
|
|
307
322
|
};
|
|
@@ -330,13 +345,13 @@ function normalizeManifest(manifest) {
|
|
|
330
345
|
if (manifest === void 0) {
|
|
331
346
|
manifest = false;
|
|
332
347
|
}
|
|
333
|
-
if (typeof manifest ===
|
|
348
|
+
if (typeof manifest === 'boolean') {
|
|
334
349
|
return manifest;
|
|
335
350
|
}
|
|
336
351
|
return Object.assign({
|
|
337
|
-
filePath:
|
|
352
|
+
filePath: '',
|
|
338
353
|
disableAssetsAnalyze: false,
|
|
339
|
-
fileName:
|
|
354
|
+
fileName: 'mf-manifest.json'
|
|
340
355
|
}, manifest);
|
|
341
356
|
}
|
|
342
357
|
var config;
|
|
@@ -345,10 +360,13 @@ function getNormalizeModuleFederationOptions() {
|
|
|
345
360
|
}
|
|
346
361
|
function getNormalizeShareItem(key) {
|
|
347
362
|
var options = getNormalizeModuleFederationOptions();
|
|
348
|
-
var shareItem = options.shared[removePathFromNpmPackage(key)] || options.shared[removePathFromNpmPackage(key) +
|
|
363
|
+
var shareItem = options.shared[removePathFromNpmPackage(key)] || options.shared[removePathFromNpmPackage(key) + '/'];
|
|
349
364
|
return shareItem;
|
|
350
365
|
}
|
|
351
366
|
function normalizeModuleFederationOptions(options) {
|
|
367
|
+
if (options.getPublicPath || options.publicPath) {
|
|
368
|
+
warn("We are ignoring the getPublicPath and publicPath options because they are natively supported by Vite\nwith the \"experimental.renderBuiltUrl\" configuration https://vitejs.dev/guide/build#advanced-base-options");
|
|
369
|
+
}
|
|
352
370
|
return config = {
|
|
353
371
|
exposes: normalizeExposes(options.exposes),
|
|
354
372
|
filename: options.filename || 'remoteEntry-[hash]',
|
|
@@ -360,11 +378,11 @@ function normalizeModuleFederationOptions(options) {
|
|
|
360
378
|
shareScope: options.shareScope || 'default',
|
|
361
379
|
shared: normalizeShared(options.shared),
|
|
362
380
|
runtimePlugins: options.runtimePlugins || [],
|
|
363
|
-
getPublicPath: options.getPublicPath,
|
|
364
381
|
implementation: options.implementation,
|
|
365
382
|
manifest: normalizeManifest(options.manifest),
|
|
366
383
|
dev: options.dev,
|
|
367
|
-
dts: options.dts
|
|
384
|
+
dts: options.dts,
|
|
385
|
+
shareStrategy: options.shareStrategy
|
|
368
386
|
};
|
|
369
387
|
}
|
|
370
388
|
|
|
@@ -382,8 +400,8 @@ function normalizeModuleFederationOptions(options) {
|
|
|
382
400
|
* @returns {string} - The encoded file name.
|
|
383
401
|
*/
|
|
384
402
|
function packageNameEncode(name) {
|
|
385
|
-
if (typeof name !==
|
|
386
|
-
return name.replace(/@/g,
|
|
403
|
+
if (typeof name !== 'string') throw new Error('A string package name is required');
|
|
404
|
+
return name.replace(/@/g, '_mf_0_').replace(/\//g, '_mf_1_').replace(/-/g, '_mf_2_').replace(/\./g, '_mf_3_');
|
|
387
405
|
}
|
|
388
406
|
/**
|
|
389
407
|
* Decodes an encoded file name back to the original package name.
|
|
@@ -391,8 +409,8 @@ function packageNameEncode(name) {
|
|
|
391
409
|
* @returns {string} - The decoded package name.
|
|
392
410
|
*/
|
|
393
411
|
function packageNameDecode(encoded) {
|
|
394
|
-
if (typeof encoded !==
|
|
395
|
-
return encoded.replace(/_mf_0_/g,
|
|
412
|
+
if (typeof encoded !== 'string') throw new Error('A string encoded file name is required');
|
|
413
|
+
return encoded.replace(/_mf_0_/g, '@').replace(/_mf_1_/g, '/').replace(/_mf_2_/g, '-').replace(/_mf_3_/g, '.');
|
|
396
414
|
}
|
|
397
415
|
|
|
398
416
|
/**
|
|
@@ -401,11 +419,11 @@ function packageNameDecode(encoded) {
|
|
|
401
419
|
function getLocalSharedImportMapPath_temp() {
|
|
402
420
|
var _getNormalizeModuleFe = getNormalizeModuleFederationOptions(),
|
|
403
421
|
name = _getNormalizeModuleFe.name;
|
|
404
|
-
return path__default["default"].resolve(
|
|
422
|
+
return path__default["default"].resolve('.__mf__temp', packageNameEncode(name), 'localSharedImportMap');
|
|
405
423
|
}
|
|
406
424
|
function writeLocalSharedImportMap_temp(content) {
|
|
407
425
|
var localSharedImportMapId = getLocalSharedImportMapPath_temp();
|
|
408
|
-
createFile(localSharedImportMapId +
|
|
426
|
+
createFile(localSharedImportMapId + '.js', '\n// Windows temporarily needs this file, https://github.com/module-federation/vite/issues/68\n' + content);
|
|
409
427
|
}
|
|
410
428
|
function createFile(filePath, content) {
|
|
411
429
|
var dir = path__default["default"].dirname(filePath);
|
|
@@ -427,16 +445,16 @@ var nodeModulesDir = function findNodeModulesDir(startDir) {
|
|
|
427
445
|
}
|
|
428
446
|
currentDir = path.dirname(currentDir);
|
|
429
447
|
}
|
|
430
|
-
return
|
|
448
|
+
return '';
|
|
431
449
|
}();
|
|
432
|
-
var virtualPackageName =
|
|
450
|
+
var virtualPackageName = '__mf__virtual';
|
|
433
451
|
if (!fs.existsSync(path.resolve(nodeModulesDir, virtualPackageName))) {
|
|
434
452
|
fs.mkdirSync(path.resolve(nodeModulesDir, virtualPackageName));
|
|
435
453
|
}
|
|
436
|
-
fs.writeFileSync(path.resolve(nodeModulesDir, virtualPackageName,
|
|
437
|
-
fs.writeFileSync(path.resolve(nodeModulesDir, virtualPackageName,
|
|
454
|
+
fs.writeFileSync(path.resolve(nodeModulesDir, virtualPackageName, 'empty.js'), '');
|
|
455
|
+
fs.writeFileSync(path.resolve(nodeModulesDir, virtualPackageName, 'package.json'), JSON.stringify({
|
|
438
456
|
name: virtualPackageName,
|
|
439
|
-
main:
|
|
457
|
+
main: 'empty.js'
|
|
440
458
|
}));
|
|
441
459
|
var patternMap = {};
|
|
442
460
|
var cacheMap = {};
|
|
@@ -450,7 +468,7 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
450
468
|
tag = '__mf_v__';
|
|
451
469
|
}
|
|
452
470
|
if (suffix === void 0) {
|
|
453
|
-
suffix =
|
|
471
|
+
suffix = '';
|
|
454
472
|
}
|
|
455
473
|
this.name = void 0;
|
|
456
474
|
this.tag = void 0;
|
|
@@ -458,13 +476,13 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
458
476
|
this.inited = false;
|
|
459
477
|
this.name = name;
|
|
460
478
|
this.tag = tag;
|
|
461
|
-
this.suffix = suffix || ((_name$split$slice$pop = name.split(
|
|
479
|
+
this.suffix = suffix || ((_name$split$slice$pop = name.split('.').slice(1).pop()) == null ? void 0 : _name$split$slice$pop.replace(/(.)/, '.$1')) || '.js';
|
|
462
480
|
if (!cacheMap[this.tag]) cacheMap[this.tag] = {};
|
|
463
481
|
cacheMap[this.tag][this.name] = this;
|
|
464
482
|
}
|
|
465
483
|
VirtualModule.findModule = function findModule(tag, str) {
|
|
466
484
|
if (str === void 0) {
|
|
467
|
-
str =
|
|
485
|
+
str = '';
|
|
468
486
|
}
|
|
469
487
|
if (!patternMap[tag]) patternMap[tag] = new RegExp("(.*" + packageNameEncode(tag) + "(.+?)" + packageNameEncode(tag) + ".*)");
|
|
470
488
|
var moduleName = (str.match(patternMap[tag]) || [])[2];
|
|
@@ -493,7 +511,15 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
493
511
|
return VirtualModule;
|
|
494
512
|
}();
|
|
495
513
|
|
|
496
|
-
var
|
|
514
|
+
var VIRTUAL_EXPOSES = 'virtual:mf-exposes';
|
|
515
|
+
function generateExposes() {
|
|
516
|
+
var options = getNormalizeModuleFederationOptions();
|
|
517
|
+
return "\n export default {\n " + Object.keys(options.exposes).map(function (key) {
|
|
518
|
+
return "\n " + JSON.stringify(key) + ": async () => {\n const importModule = await import(" + JSON.stringify(options.exposes[key]["import"]) + ")\n const exportModule = {}\n Object.assign(exportModule, importModule)\n Object.defineProperty(exportModule, \"__esModule\", {\n value: true,\n enumerable: false\n })\n return exportModule\n }\n ";
|
|
519
|
+
}).join(',') + "\n }\n ";
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
var virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
497
523
|
function writeRuntimeInitStatus() {
|
|
498
524
|
virtualRuntimeInitStatus.writeSync("\n let initResolve, initReject\n const initPromise = new Promise((re, rj) => {\n initResolve = re\n initReject = rj\n })\n export {\n initPromise,\n initResolve,\n initReject\n }\n ");
|
|
499
525
|
}
|
|
@@ -502,7 +528,7 @@ var cacheRemoteMap = {};
|
|
|
502
528
|
var LOAD_REMOTE_TAG = '__loadRemote__';
|
|
503
529
|
function getRemoteVirtualModule(remote, command) {
|
|
504
530
|
if (!cacheRemoteMap[remote]) {
|
|
505
|
-
cacheRemoteMap[remote] = new VirtualModule(remote, LOAD_REMOTE_TAG,
|
|
531
|
+
cacheRemoteMap[remote] = new VirtualModule(remote, LOAD_REMOTE_TAG, '.js');
|
|
506
532
|
cacheRemoteMap[remote].writeSync(generateRemotes(remote, command));
|
|
507
533
|
}
|
|
508
534
|
var virtual = cacheRemoteMap[remote];
|
|
@@ -519,7 +545,7 @@ function getUsedRemotesMap() {
|
|
|
519
545
|
return usedRemotesMap;
|
|
520
546
|
}
|
|
521
547
|
function generateRemotes(id, command) {
|
|
522
|
-
return "\n const {loadRemote} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadRemote(" + JSON.stringify(id) + "))\n const exportModule = " + (command !==
|
|
548
|
+
return "\n const {loadRemote} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadRemote(" + JSON.stringify(id) + "))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "initPromise.then(_ => res)\n module.exports = exportModule\n ";
|
|
523
549
|
}
|
|
524
550
|
|
|
525
551
|
/**
|
|
@@ -529,10 +555,10 @@ function generateRemotes(id, command) {
|
|
|
529
555
|
*/
|
|
530
556
|
// *** __prebuild__
|
|
531
557
|
var preBuildCacheMap = {};
|
|
532
|
-
var PREBUILD_TAG =
|
|
558
|
+
var PREBUILD_TAG = '__prebuild__';
|
|
533
559
|
function writePreBuildLibPath(pkg) {
|
|
534
560
|
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(pkg, PREBUILD_TAG);
|
|
535
|
-
preBuildCacheMap[pkg].writeSync(
|
|
561
|
+
preBuildCacheMap[pkg].writeSync('');
|
|
536
562
|
}
|
|
537
563
|
function getPreBuildLibImportId(pkg) {
|
|
538
564
|
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(pkg, PREBUILD_TAG);
|
|
@@ -540,15 +566,15 @@ function getPreBuildLibImportId(pkg) {
|
|
|
540
566
|
return importId;
|
|
541
567
|
}
|
|
542
568
|
// *** __loadShare__
|
|
543
|
-
var LOAD_SHARE_TAG =
|
|
569
|
+
var LOAD_SHARE_TAG = '__loadShare__';
|
|
544
570
|
var loadShareCacheMap = {};
|
|
545
571
|
function getLoadShareModulePath(pkg) {
|
|
546
|
-
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = new VirtualModule(pkg, LOAD_SHARE_TAG,
|
|
572
|
+
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = new VirtualModule(pkg, LOAD_SHARE_TAG, '.js');
|
|
547
573
|
var filepath = loadShareCacheMap[pkg].getPath();
|
|
548
574
|
return filepath;
|
|
549
575
|
}
|
|
550
576
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
551
|
-
loadShareCacheMap[pkg].writeSync("\n \n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !==
|
|
577
|
+
loadShareCacheMap[pkg].writeSync("\n \n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !== 'build' ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}}))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
552
578
|
}
|
|
553
579
|
|
|
554
580
|
var usedShares = new Set();
|
|
@@ -559,7 +585,7 @@ function addUsedShares(pkg) {
|
|
|
559
585
|
usedShares.add(pkg);
|
|
560
586
|
}
|
|
561
587
|
// *** Expose locally provided shared modules here
|
|
562
|
-
new VirtualModule(
|
|
588
|
+
new VirtualModule('localSharedImportMap');
|
|
563
589
|
function getLocalSharedImportMapPath() {
|
|
564
590
|
return getLocalSharedImportMapPath_temp();
|
|
565
591
|
// return localSharedImportMapModule.getPath()
|
|
@@ -577,7 +603,7 @@ function generateLocalSharedImportMap() {
|
|
|
577
603
|
var options = getNormalizeModuleFederationOptions();
|
|
578
604
|
return "\n const importMap = {\n " + Array.from(getUsedShares()).map(function (pkg) {
|
|
579
605
|
return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
|
|
580
|
-
}).join(
|
|
606
|
+
}).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
|
|
581
607
|
var shareItem = getNormalizeShareItem(key);
|
|
582
608
|
return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(key) + ",\n version: " + JSON.stringify(shareItem.version) + ",\n scope: [" + JSON.stringify(shareItem.scope) + "],\n loaded: false,\n from: " + JSON.stringify(options.name) + ",\n async get () {\n usedShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = importMap \n const res = await pkgDynamicImport()\n const exportModule = {...res}\n // All npm packages pre-built by vite will be converted to esm\n Object.defineProperty(exportModule, \"__esModule\", {\n value: true,\n enumerable: false\n })\n return function () {\n return exportModule\n }\n },\n shareConfig: {\n singleton: " + shareItem.shareConfig.singleton + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }\n }\n ";
|
|
583
609
|
}).join(',') + "\n }\n const usedRemotes = [" + Object.keys(getUsedRemotesMap()).map(function (key) {
|
|
@@ -592,17 +618,15 @@ function generateRemoteEntry(options) {
|
|
|
592
618
|
});
|
|
593
619
|
return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
|
|
594
620
|
return item[1];
|
|
595
|
-
}).join('\n') + "\n\n const
|
|
596
|
-
return "\n " + JSON.stringify(key) + ": async () => {\n const importModule = await import(" + JSON.stringify(options.exposes[key]["import"]) + ")\n const exportModule = {}\n Object.assign(exportModule, importModule)\n Object.defineProperty(exportModule, \"__esModule\", {\n value: true,\n enumerable: false\n })\n return exportModule\n }\n ";
|
|
597
|
-
}).join(',') + "\n }\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n async function init(shared = {}) {\n const initRes = runtimeInit({\n name: " + JSON.stringify(options.name) + ",\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
|
|
621
|
+
}).join('\n') + "\n import exposesMap from \"" + VIRTUAL_EXPOSES + "\"\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n async function init(shared = {}) {\n const initRes = runtimeInit({\n name: " + JSON.stringify(options.name) + ",\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
|
|
598
622
|
return item[0] + "()";
|
|
599
|
-
}).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n initResolve(initRes)\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
|
|
623
|
+
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: " + options.shareStrategy : '') + "\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n initResolve(initRes)\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
|
|
600
624
|
}
|
|
601
625
|
/**
|
|
602
626
|
* Inject entry file, automatically init when used as host,
|
|
603
627
|
* and will not inject remoteEntry
|
|
604
628
|
*/
|
|
605
|
-
var hostAutoInitModule = new VirtualModule(
|
|
629
|
+
var hostAutoInitModule = new VirtualModule('hostAutoInit');
|
|
606
630
|
function writeHostAutoInit() {
|
|
607
631
|
hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
|
|
608
632
|
}
|
|
@@ -624,20 +648,19 @@ var Manifest = function Manifest() {
|
|
|
624
648
|
var name = mfOptions.name,
|
|
625
649
|
filename = mfOptions.filename,
|
|
626
650
|
manifestOptions = mfOptions.manifest;
|
|
627
|
-
var mfManifestName =
|
|
651
|
+
var mfManifestName = '';
|
|
628
652
|
if (manifestOptions === true) {
|
|
629
|
-
mfManifestName =
|
|
653
|
+
mfManifestName = 'mf-manifest.json';
|
|
630
654
|
}
|
|
631
|
-
if (typeof manifestOptions !==
|
|
632
|
-
mfManifestName = path.join((manifestOptions == null ? void 0 : manifestOptions.filePath) ||
|
|
655
|
+
if (typeof manifestOptions !== 'boolean') {
|
|
656
|
+
mfManifestName = path.join((manifestOptions == null ? void 0 : manifestOptions.filePath) || '', (manifestOptions == null ? void 0 : manifestOptions.fileName) || '');
|
|
633
657
|
}
|
|
634
658
|
var extensions;
|
|
635
659
|
var root;
|
|
636
660
|
var remoteEntryFile;
|
|
637
|
-
var publicPath;
|
|
638
661
|
var _command;
|
|
639
662
|
return [{
|
|
640
|
-
name: '
|
|
663
|
+
name: 'module-federation-manifest',
|
|
641
664
|
apply: 'serve',
|
|
642
665
|
configureServer: function configureServer(server) {
|
|
643
666
|
server.middlewares.use(function (req, res, next) {
|
|
@@ -645,10 +668,10 @@ var Manifest = function Manifest() {
|
|
|
645
668
|
next();
|
|
646
669
|
return;
|
|
647
670
|
}
|
|
648
|
-
if (req.url === mfManifestName.replace(/^\/?/,
|
|
671
|
+
if (req.url === mfManifestName.replace(/^\/?/, '/')) {
|
|
649
672
|
res.setHeader('Content-Type', 'application/json');
|
|
650
673
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
651
|
-
res.end(JSON.stringify({
|
|
674
|
+
res.end(JSON.stringify(_extends({}, generateMFManifest({}), {
|
|
652
675
|
id: name,
|
|
653
676
|
name: name,
|
|
654
677
|
metaData: {
|
|
@@ -673,70 +696,16 @@ var Manifest = function Manifest() {
|
|
|
673
696
|
name: ''
|
|
674
697
|
},
|
|
675
698
|
globalName: name,
|
|
676
|
-
pluginVersion: '0.2.5'
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
shared: Array.from(getUsedShares()).map(function (shareKey) {
|
|
680
|
-
var shareItem = getNormalizeShareItem(shareKey);
|
|
681
|
-
return {
|
|
682
|
-
id: name + ":" + shareKey,
|
|
683
|
-
name: shareKey,
|
|
684
|
-
version: shareItem.version,
|
|
685
|
-
requiredVersion: shareItem.shareConfig.requiredVersion,
|
|
686
|
-
assets: {
|
|
687
|
-
js: {
|
|
688
|
-
async: [],
|
|
689
|
-
sync: []
|
|
690
|
-
},
|
|
691
|
-
css: {
|
|
692
|
-
async: [],
|
|
693
|
-
sync: []
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
}),
|
|
698
|
-
remotes: function () {
|
|
699
|
-
var remotes = [];
|
|
700
|
-
var usedRemotesMap = getUsedRemotesMap();
|
|
701
|
-
Object.keys(usedRemotesMap).forEach(function (remoteKey) {
|
|
702
|
-
var usedModules = Array.from(usedRemotesMap[remoteKey]);
|
|
703
|
-
usedModules.forEach(function (moduleKey) {
|
|
704
|
-
remotes.push({
|
|
705
|
-
federationContainerName: mfOptions.remotes[remoteKey].entry,
|
|
706
|
-
moduleName: moduleKey.replace(remoteKey, '').replace('/', ''),
|
|
707
|
-
alias: remoteKey,
|
|
708
|
-
entry: '*'
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
return remotes;
|
|
713
|
-
}(),
|
|
714
|
-
exposes: Object.keys(mfOptions.exposes).map(function (key) {
|
|
715
|
-
var formatKey = key.replace('./', '');
|
|
716
|
-
return {
|
|
717
|
-
id: name + ':' + formatKey,
|
|
718
|
-
name: formatKey,
|
|
719
|
-
assets: {
|
|
720
|
-
js: {
|
|
721
|
-
async: [],
|
|
722
|
-
sync: []
|
|
723
|
-
},
|
|
724
|
-
css: {
|
|
725
|
-
sync: [],
|
|
726
|
-
async: []
|
|
727
|
-
}
|
|
728
|
-
},
|
|
729
|
-
path: key
|
|
730
|
-
};
|
|
731
|
-
})
|
|
732
|
-
}));
|
|
699
|
+
pluginVersion: '0.2.5'
|
|
700
|
+
}
|
|
701
|
+
})));
|
|
733
702
|
} else {
|
|
734
703
|
next();
|
|
735
704
|
}
|
|
736
705
|
});
|
|
737
706
|
}
|
|
738
707
|
}, {
|
|
739
|
-
name: '
|
|
708
|
+
name: 'module-federation-manifest',
|
|
740
709
|
enforce: 'post',
|
|
741
710
|
config: function config(_config, _ref) {
|
|
742
711
|
var command = _ref.command;
|
|
@@ -747,10 +716,10 @@ var Manifest = function Manifest() {
|
|
|
747
716
|
configResolved: function configResolved(config) {
|
|
748
717
|
root = config.root;
|
|
749
718
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
750
|
-
|
|
751
|
-
if (_command ===
|
|
719
|
+
config.base ? config.base.replace(/\/?$/, '/') : 'auto';
|
|
720
|
+
if (_command === 'serve') {
|
|
752
721
|
var origin = config.server.origin;
|
|
753
|
-
|
|
722
|
+
origin ? origin.replace(/\/?$/, '/') : 'auto';
|
|
754
723
|
}
|
|
755
724
|
},
|
|
756
725
|
generateBundle: function generateBundle(options, bundle) {
|
|
@@ -792,7 +761,7 @@ var Manifest = function Manifest() {
|
|
|
792
761
|
var _Object$entries$_i = _Object$entries[_i],
|
|
793
762
|
fileName = _Object$entries$_i[0],
|
|
794
763
|
fileData = _Object$entries$_i[1];
|
|
795
|
-
if (mfOptions.filename.replace(/[\[\]]/g,
|
|
764
|
+
if (mfOptions.filename.replace(/[\[\]]/g, '_') === fileData.name || fileData.name === 'remoteEntry') {
|
|
796
765
|
remoteEntryFile = fileData.fileName;
|
|
797
766
|
}
|
|
798
767
|
if (fileData.type === 'chunk') {
|
|
@@ -804,7 +773,7 @@ var Manifest = function Manifest() {
|
|
|
804
773
|
// 检查模块是否在 preloadModules 列表中
|
|
805
774
|
for (var _iterator2 = _createForOfIteratorHelperLoose(exposesModules), _step2; !(_step2 = _iterator2()).done;) {
|
|
806
775
|
var preloadModule = _step2.value;
|
|
807
|
-
var formatPreloadModule = preloadModule.replace(
|
|
776
|
+
var formatPreloadModule = preloadModule.replace('./', '');
|
|
808
777
|
if (isModuleMatched(relativeModulePath, formatPreloadModule)) {
|
|
809
778
|
var _filesContainingModul;
|
|
810
779
|
if (!filesContainingModules[preloadModule]) {
|
|
@@ -823,12 +792,11 @@ var Manifest = function Manifest() {
|
|
|
823
792
|
}
|
|
824
793
|
}
|
|
825
794
|
}
|
|
826
|
-
;
|
|
827
795
|
var fileToShareKey = {};
|
|
828
796
|
return Promise.resolve(Promise.all(Array.from(getUsedShares()).map(function (shareKey) {
|
|
829
797
|
try {
|
|
830
798
|
return Promise.resolve(_this.resolve(getPreBuildLibImportId(shareKey))).then(function (_this$resolve) {
|
|
831
|
-
var file = _this$resolve.id.split(
|
|
799
|
+
var file = _this$resolve.id.split('?')[0];
|
|
832
800
|
fileToShareKey[file] = shareKey;
|
|
833
801
|
});
|
|
834
802
|
} catch (e) {
|
|
@@ -868,7 +836,7 @@ var Manifest = function Manifest() {
|
|
|
868
836
|
_this.emitFile({
|
|
869
837
|
type: 'asset',
|
|
870
838
|
fileName: mfManifestName,
|
|
871
|
-
source: generateMFManifest(filesContainingModules)
|
|
839
|
+
source: JSON.stringify(generateMFManifest(filesContainingModules))
|
|
872
840
|
});
|
|
873
841
|
});
|
|
874
842
|
} catch (e) {
|
|
@@ -899,8 +867,7 @@ var Manifest = function Manifest() {
|
|
|
899
867
|
});
|
|
900
868
|
// @ts-ignore
|
|
901
869
|
var shared = Array.from(getUsedShares()).map(function (shareKey) {
|
|
902
|
-
|
|
903
|
-
if (!preloadMap[shareKey]) return;
|
|
870
|
+
var _preloadMap$shareKey, _preloadMap$shareKey2;
|
|
904
871
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
905
872
|
return {
|
|
906
873
|
id: name + ":" + shareKey,
|
|
@@ -909,8 +876,8 @@ var Manifest = function Manifest() {
|
|
|
909
876
|
requiredVersion: shareItem.shareConfig.requiredVersion,
|
|
910
877
|
assets: {
|
|
911
878
|
js: {
|
|
912
|
-
async: preloadMap[shareKey].async,
|
|
913
|
-
sync: preloadMap[shareKey].sync
|
|
879
|
+
async: (preloadMap == null || (_preloadMap$shareKey = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey.async) || [],
|
|
880
|
+
sync: (preloadMap == null || (_preloadMap$shareKey2 = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey2.sync) || []
|
|
914
881
|
},
|
|
915
882
|
css: {
|
|
916
883
|
async: [],
|
|
@@ -922,17 +889,17 @@ var Manifest = function Manifest() {
|
|
|
922
889
|
return item;
|
|
923
890
|
});
|
|
924
891
|
var exposes = Object.keys(options.exposes).map(function (key) {
|
|
892
|
+
var _preloadMap$sourceFil, _preloadMap$sourceFil2;
|
|
925
893
|
// assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
|
|
926
894
|
var formatKey = key.replace('./', '');
|
|
927
895
|
var sourceFile = options.exposes[key]["import"];
|
|
928
|
-
if (!preloadMap[sourceFile]) return;
|
|
929
896
|
return {
|
|
930
897
|
id: name + ':' + formatKey,
|
|
931
898
|
name: formatKey,
|
|
932
899
|
assets: {
|
|
933
900
|
js: {
|
|
934
|
-
async: preloadMap[sourceFile].async,
|
|
935
|
-
sync: preloadMap[sourceFile].sync
|
|
901
|
+
async: (preloadMap == null || (_preloadMap$sourceFil = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil.async) || [],
|
|
902
|
+
sync: (preloadMap == null || (_preloadMap$sourceFil2 = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil2.sync) || []
|
|
936
903
|
},
|
|
937
904
|
css: {
|
|
938
905
|
sync: [],
|
|
@@ -963,14 +930,13 @@ var Manifest = function Manifest() {
|
|
|
963
930
|
// "api": "@mf-types.d.ts"
|
|
964
931
|
},
|
|
965
932
|
globalName: name,
|
|
966
|
-
pluginVersion: '0.2.5'
|
|
967
|
-
publicPath: publicPath
|
|
933
|
+
pluginVersion: '0.2.5'
|
|
968
934
|
},
|
|
969
935
|
shared: shared,
|
|
970
936
|
remotes: remotes,
|
|
971
937
|
exposes: exposes
|
|
972
938
|
};
|
|
973
|
-
return
|
|
939
|
+
return result;
|
|
974
940
|
}
|
|
975
941
|
};
|
|
976
942
|
|
|
@@ -979,20 +945,21 @@ var _resolve,
|
|
|
979
945
|
_resolve = resolve;
|
|
980
946
|
});
|
|
981
947
|
var parsePromise = promise;
|
|
948
|
+
var exposesParseEnd = false;
|
|
982
949
|
var parseStartSet = new Set();
|
|
983
950
|
var parseEndSet = new Set();
|
|
984
951
|
function pluginModuleParseEnd (excludeFn) {
|
|
985
952
|
return [{
|
|
986
|
-
name:
|
|
987
|
-
apply:
|
|
953
|
+
name: '_',
|
|
954
|
+
apply: 'serve',
|
|
988
955
|
config: function config() {
|
|
989
956
|
// No waiting in development mode
|
|
990
957
|
_resolve(1);
|
|
991
958
|
}
|
|
992
959
|
}, {
|
|
993
|
-
enforce:
|
|
994
|
-
name:
|
|
995
|
-
apply:
|
|
960
|
+
enforce: 'pre',
|
|
961
|
+
name: 'parseStart',
|
|
962
|
+
apply: 'build',
|
|
996
963
|
load: function load(id) {
|
|
997
964
|
if (excludeFn(id)) {
|
|
998
965
|
return;
|
|
@@ -1000,16 +967,20 @@ function pluginModuleParseEnd (excludeFn) {
|
|
|
1000
967
|
parseStartSet.add(id);
|
|
1001
968
|
}
|
|
1002
969
|
}, {
|
|
1003
|
-
enforce:
|
|
1004
|
-
name:
|
|
1005
|
-
apply:
|
|
970
|
+
enforce: 'post',
|
|
971
|
+
name: 'parseEnd',
|
|
972
|
+
apply: 'build',
|
|
1006
973
|
moduleParsed: function moduleParsed(module) {
|
|
1007
974
|
var id = module.id;
|
|
1008
975
|
if (excludeFn(id)) {
|
|
1009
976
|
return;
|
|
1010
977
|
}
|
|
978
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
979
|
+
// When the entry JS file is empty and only contains exposes export code, it’s necessary to wait for the exposes modules to be resolved in order to collect the dependencies being used.
|
|
980
|
+
exposesParseEnd = true;
|
|
981
|
+
}
|
|
1011
982
|
parseEndSet.add(id);
|
|
1012
|
-
if (parseStartSet.size === parseEndSet.size) {
|
|
983
|
+
if (exposesParseEnd && parseStartSet.size === parseEndSet.size) {
|
|
1013
984
|
_resolve(1);
|
|
1014
985
|
}
|
|
1015
986
|
}
|
|
@@ -1025,6 +996,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1025
996
|
if (id === REMOTE_ENTRY_ID) {
|
|
1026
997
|
return REMOTE_ENTRY_ID;
|
|
1027
998
|
}
|
|
999
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
1000
|
+
return VIRTUAL_EXPOSES;
|
|
1001
|
+
}
|
|
1028
1002
|
},
|
|
1029
1003
|
load: function load(id) {
|
|
1030
1004
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1032,6 +1006,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1032
1006
|
return generateRemoteEntry(getNormalizeModuleFederationOptions());
|
|
1033
1007
|
});
|
|
1034
1008
|
}
|
|
1009
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
1010
|
+
return generateExposes();
|
|
1011
|
+
}
|
|
1035
1012
|
},
|
|
1036
1013
|
transform: function transform(code, id) {
|
|
1037
1014
|
try {
|
|
@@ -1041,6 +1018,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1041
1018
|
return generateRemoteEntry(getNormalizeModuleFederationOptions());
|
|
1042
1019
|
}));
|
|
1043
1020
|
}
|
|
1021
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
1022
|
+
return Promise.resolve(generateExposes());
|
|
1023
|
+
}
|
|
1044
1024
|
return Promise.resolve();
|
|
1045
1025
|
} catch (e) {
|
|
1046
1026
|
return Promise.reject(e);
|
|
@@ -1053,14 +1033,14 @@ pluginutils.createFilter();
|
|
|
1053
1033
|
function pluginProxyRemotes (options) {
|
|
1054
1034
|
var remotes = options.remotes;
|
|
1055
1035
|
return {
|
|
1056
|
-
name:
|
|
1036
|
+
name: 'proxyRemotes',
|
|
1057
1037
|
config: function config(_config, _ref) {
|
|
1058
1038
|
var _command = _ref.command;
|
|
1059
1039
|
Object.keys(remotes).forEach(function (key) {
|
|
1060
1040
|
var remote = remotes[key];
|
|
1061
1041
|
_config.resolve.alias.push({
|
|
1062
1042
|
find: new RegExp("^(" + remote.name + "(/.*|$))"),
|
|
1063
|
-
replacement:
|
|
1043
|
+
replacement: '$1',
|
|
1064
1044
|
customResolver: function customResolver(source) {
|
|
1065
1045
|
var remoteModule = getRemoteVirtualModule(source, _command);
|
|
1066
1046
|
addUsedRemote(remote.name, source);
|
|
@@ -1114,8 +1094,8 @@ function proxySharedModule(options) {
|
|
|
1114
1094
|
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
1115
1095
|
var _config;
|
|
1116
1096
|
return [{
|
|
1117
|
-
name:
|
|
1118
|
-
enforce:
|
|
1097
|
+
name: 'generateLocalSharedImportMap',
|
|
1098
|
+
enforce: 'post',
|
|
1119
1099
|
load: function load(id) {
|
|
1120
1100
|
if (id.includes(getLocalSharedImportMapPath())) {
|
|
1121
1101
|
return parsePromise.then(function (_) {
|
|
@@ -1140,11 +1120,11 @@ function proxySharedModule(options) {
|
|
|
1140
1120
|
var _config2$resolve$alia, _config2$resolve$alia2;
|
|
1141
1121
|
var command = _ref.command;
|
|
1142
1122
|
(_config2$resolve$alia = _config2.resolve.alias).push.apply(_config2$resolve$alia, Object.keys(shared).map(function (key) {
|
|
1143
|
-
var pattern = key.endsWith(
|
|
1123
|
+
var pattern = key.endsWith('/') ? "(^" + key.replace(/\/$/, '') + "(/.+)?$)" : "(^" + key + "$)";
|
|
1144
1124
|
return {
|
|
1145
1125
|
// Intercept all shared requests and proxy them to loadShare
|
|
1146
1126
|
find: new RegExp(pattern),
|
|
1147
|
-
replacement:
|
|
1127
|
+
replacement: '$1',
|
|
1148
1128
|
customResolver: function customResolver(source, importer) {
|
|
1149
1129
|
if (/\.css$/.test(source)) return;
|
|
1150
1130
|
var loadSharePath = getLoadShareModulePath(source);
|
|
@@ -1158,7 +1138,7 @@ function proxySharedModule(options) {
|
|
|
1158
1138
|
}));
|
|
1159
1139
|
var savePrebuild = new PromiseStore();
|
|
1160
1140
|
(_config2$resolve$alia2 = _config2.resolve.alias).push.apply(_config2$resolve$alia2, Object.keys(shared).map(function (key) {
|
|
1161
|
-
return command ===
|
|
1141
|
+
return command === 'build' ? {
|
|
1162
1142
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1163
1143
|
replacement: function replacement($1) {
|
|
1164
1144
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, $1).name;
|
|
@@ -1166,7 +1146,7 @@ function proxySharedModule(options) {
|
|
|
1166
1146
|
}
|
|
1167
1147
|
} : {
|
|
1168
1148
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1169
|
-
replacement:
|
|
1149
|
+
replacement: '$1',
|
|
1170
1150
|
customResolver: function customResolver(source, importer) {
|
|
1171
1151
|
try {
|
|
1172
1152
|
var _this = this;
|
|
@@ -1192,8 +1172,8 @@ function proxySharedModule(options) {
|
|
|
1192
1172
|
}));
|
|
1193
1173
|
}
|
|
1194
1174
|
}, {
|
|
1195
|
-
name:
|
|
1196
|
-
apply:
|
|
1175
|
+
name: 'watchLocalSharedImportMap',
|
|
1176
|
+
apply: 'serve',
|
|
1197
1177
|
config: function config(_config3) {
|
|
1198
1178
|
_config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
|
|
1199
1179
|
exclude: [getLocalSharedImportMapPath()]
|
|
@@ -1250,7 +1230,7 @@ function federation(mfUserOptions) {
|
|
|
1250
1230
|
var name = options.name,
|
|
1251
1231
|
shared = options.shared,
|
|
1252
1232
|
filename = options.filename;
|
|
1253
|
-
if (!name) throw new Error(
|
|
1233
|
+
if (!name) throw new Error('name is required');
|
|
1254
1234
|
return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin].concat(addEntry({
|
|
1255
1235
|
entryName: 'remoteEntry',
|
|
1256
1236
|
entryPath: REMOTE_ENTRY_ID,
|
|
@@ -1258,6 +1238,9 @@ function federation(mfUserOptions) {
|
|
|
1258
1238
|
}), addEntry({
|
|
1259
1239
|
entryName: 'hostInit',
|
|
1260
1240
|
entryPath: getHostAutoInitPath()
|
|
1241
|
+
}), addEntry({
|
|
1242
|
+
entryName: 'virtualExposes',
|
|
1243
|
+
entryPath: VIRTUAL_EXPOSES
|
|
1261
1244
|
}), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
|
|
1262
1245
|
return id.includes(getHostAutoInitImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
|
|
1263
1246
|
}), proxySharedModule({
|
|
@@ -1267,6 +1250,7 @@ function federation(mfUserOptions) {
|
|
|
1267
1250
|
enforce: 'post',
|
|
1268
1251
|
config: function config(_config, _ref) {
|
|
1269
1252
|
var _config$optimizeDeps;
|
|
1253
|
+
// TODO: singleton
|
|
1270
1254
|
_config.resolve.alias.push({
|
|
1271
1255
|
find: '@module-federation/runtime',
|
|
1272
1256
|
replacement: require.resolve('@module-federation/runtime')
|