@module-federation/vite 1.0.0-alpha-0b760f6 → 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 -48
- 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 +47 -32
- 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.esm.js
CHANGED
|
@@ -11,13 +11,13 @@ var addEntry = function addEntry(_ref) {
|
|
|
11
11
|
var entryName = _ref.entryName,
|
|
12
12
|
entryPath = _ref.entryPath,
|
|
13
13
|
fileName = _ref.fileName;
|
|
14
|
-
var devEntryPath = entryPath.startsWith(
|
|
14
|
+
var devEntryPath = entryPath.startsWith('virtual:mf') ? '/@id/' + entryPath : entryPath;
|
|
15
15
|
var entryFiles = [];
|
|
16
16
|
var htmlFilePath;
|
|
17
17
|
var _command;
|
|
18
18
|
return [{
|
|
19
19
|
name: 'add-entry',
|
|
20
|
-
apply:
|
|
20
|
+
apply: 'serve',
|
|
21
21
|
config: function config(_config, _ref2) {
|
|
22
22
|
var command = _ref2.command;
|
|
23
23
|
_command = command;
|
|
@@ -43,8 +43,8 @@ var addEntry = function addEntry(_ref) {
|
|
|
43
43
|
return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
|
|
44
44
|
}
|
|
45
45
|
}, {
|
|
46
|
-
name:
|
|
47
|
-
enforce:
|
|
46
|
+
name: 'add-entry',
|
|
47
|
+
enforce: 'post',
|
|
48
48
|
configResolved: function configResolved(config) {
|
|
49
49
|
var inputOptions = config.build.rollupOptions.input;
|
|
50
50
|
if (!inputOptions) {
|
|
@@ -61,8 +61,8 @@ var addEntry = function addEntry(_ref) {
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
buildStart: function buildStart() {
|
|
64
|
-
if (_command ===
|
|
65
|
-
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes(
|
|
64
|
+
if (_command === 'serve') return;
|
|
65
|
+
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes('[hash');
|
|
66
66
|
var emitFileOptions = {
|
|
67
67
|
name: entryName,
|
|
68
68
|
type: 'chunk',
|
|
@@ -99,10 +99,10 @@ var addEntry = function addEntry(_ref) {
|
|
|
99
99
|
function PluginDevProxyModuleTopLevelAwait() {
|
|
100
100
|
var filterFunction = createFilter();
|
|
101
101
|
return {
|
|
102
|
-
name:
|
|
103
|
-
apply:
|
|
102
|
+
name: 'dev-proxy-module-top-level-await',
|
|
103
|
+
apply: 'serve',
|
|
104
104
|
transform: function transform(code, id) {
|
|
105
|
-
if (!code.includes(
|
|
105
|
+
if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
108
|
if (!filterFunction(id)) return null;
|
|
@@ -186,6 +186,15 @@ function _createForOfIteratorHelperLoose(r, e) {
|
|
|
186
186
|
}
|
|
187
187
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
188
188
|
}
|
|
189
|
+
function _extends() {
|
|
190
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
191
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
192
|
+
var t = arguments[e];
|
|
193
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
194
|
+
}
|
|
195
|
+
return n;
|
|
196
|
+
}, _extends.apply(null, arguments);
|
|
197
|
+
}
|
|
189
198
|
function _unsupportedIterableToArray(r, a) {
|
|
190
199
|
if (r) {
|
|
191
200
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -194,6 +203,12 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
|
|
206
|
+
var warn = function warn(message) {
|
|
207
|
+
return message.split('\n').forEach(function (msg) {
|
|
208
|
+
return console.warn('\x1b[33m%s\x1b[0m', msg);
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
197
212
|
function normalizeExposesItem(key, item) {
|
|
198
213
|
var importPath = '';
|
|
199
214
|
if (typeof item === 'string') {
|
|
@@ -267,7 +282,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
267
282
|
from: '',
|
|
268
283
|
shareConfig: {
|
|
269
284
|
singleton: false,
|
|
270
|
-
requiredVersion: "^" + version
|
|
285
|
+
requiredVersion: version ? "^" + version : '*'
|
|
271
286
|
}
|
|
272
287
|
};
|
|
273
288
|
}
|
|
@@ -278,7 +293,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
278
293
|
scope: shareItem.shareScope || 'default',
|
|
279
294
|
shareConfig: {
|
|
280
295
|
singleton: shareItem.singleton || false,
|
|
281
|
-
requiredVersion: shareItem.requiredVersion || "^" + version
|
|
296
|
+
requiredVersion: shareItem.requiredVersion || (version ? "^" + version : '*'),
|
|
282
297
|
strictVersion: !!shareItem.strictVersion
|
|
283
298
|
}
|
|
284
299
|
};
|
|
@@ -307,13 +322,13 @@ function normalizeManifest(manifest) {
|
|
|
307
322
|
if (manifest === void 0) {
|
|
308
323
|
manifest = false;
|
|
309
324
|
}
|
|
310
|
-
if (typeof manifest ===
|
|
325
|
+
if (typeof manifest === 'boolean') {
|
|
311
326
|
return manifest;
|
|
312
327
|
}
|
|
313
328
|
return Object.assign({
|
|
314
|
-
filePath:
|
|
329
|
+
filePath: '',
|
|
315
330
|
disableAssetsAnalyze: false,
|
|
316
|
-
fileName:
|
|
331
|
+
fileName: 'mf-manifest.json'
|
|
317
332
|
}, manifest);
|
|
318
333
|
}
|
|
319
334
|
var config;
|
|
@@ -322,10 +337,13 @@ function getNormalizeModuleFederationOptions() {
|
|
|
322
337
|
}
|
|
323
338
|
function getNormalizeShareItem(key) {
|
|
324
339
|
var options = getNormalizeModuleFederationOptions();
|
|
325
|
-
var shareItem = options.shared[removePathFromNpmPackage(key)] || options.shared[removePathFromNpmPackage(key) +
|
|
340
|
+
var shareItem = options.shared[removePathFromNpmPackage(key)] || options.shared[removePathFromNpmPackage(key) + '/'];
|
|
326
341
|
return shareItem;
|
|
327
342
|
}
|
|
328
343
|
function normalizeModuleFederationOptions(options) {
|
|
344
|
+
if (options.getPublicPath || options.publicPath) {
|
|
345
|
+
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");
|
|
346
|
+
}
|
|
329
347
|
return config = {
|
|
330
348
|
exposes: normalizeExposes(options.exposes),
|
|
331
349
|
filename: options.filename || 'remoteEntry-[hash]',
|
|
@@ -337,11 +355,11 @@ function normalizeModuleFederationOptions(options) {
|
|
|
337
355
|
shareScope: options.shareScope || 'default',
|
|
338
356
|
shared: normalizeShared(options.shared),
|
|
339
357
|
runtimePlugins: options.runtimePlugins || [],
|
|
340
|
-
getPublicPath: options.getPublicPath,
|
|
341
358
|
implementation: options.implementation,
|
|
342
359
|
manifest: normalizeManifest(options.manifest),
|
|
343
360
|
dev: options.dev,
|
|
344
|
-
dts: options.dts
|
|
361
|
+
dts: options.dts,
|
|
362
|
+
shareStrategy: options.shareStrategy
|
|
345
363
|
};
|
|
346
364
|
}
|
|
347
365
|
|
|
@@ -359,8 +377,8 @@ function normalizeModuleFederationOptions(options) {
|
|
|
359
377
|
* @returns {string} - The encoded file name.
|
|
360
378
|
*/
|
|
361
379
|
function packageNameEncode(name) {
|
|
362
|
-
if (typeof name !==
|
|
363
|
-
return name.replace(/@/g,
|
|
380
|
+
if (typeof name !== 'string') throw new Error('A string package name is required');
|
|
381
|
+
return name.replace(/@/g, '_mf_0_').replace(/\//g, '_mf_1_').replace(/-/g, '_mf_2_').replace(/\./g, '_mf_3_');
|
|
364
382
|
}
|
|
365
383
|
/**
|
|
366
384
|
* Decodes an encoded file name back to the original package name.
|
|
@@ -368,8 +386,8 @@ function packageNameEncode(name) {
|
|
|
368
386
|
* @returns {string} - The decoded package name.
|
|
369
387
|
*/
|
|
370
388
|
function packageNameDecode(encoded) {
|
|
371
|
-
if (typeof encoded !==
|
|
372
|
-
return encoded.replace(/_mf_0_/g,
|
|
389
|
+
if (typeof encoded !== 'string') throw new Error('A string encoded file name is required');
|
|
390
|
+
return encoded.replace(/_mf_0_/g, '@').replace(/_mf_1_/g, '/').replace(/_mf_2_/g, '-').replace(/_mf_3_/g, '.');
|
|
373
391
|
}
|
|
374
392
|
|
|
375
393
|
/**
|
|
@@ -378,11 +396,11 @@ function packageNameDecode(encoded) {
|
|
|
378
396
|
function getLocalSharedImportMapPath_temp() {
|
|
379
397
|
var _getNormalizeModuleFe = getNormalizeModuleFederationOptions(),
|
|
380
398
|
name = _getNormalizeModuleFe.name;
|
|
381
|
-
return path__default.resolve(
|
|
399
|
+
return path__default.resolve('.__mf__temp', packageNameEncode(name), 'localSharedImportMap');
|
|
382
400
|
}
|
|
383
401
|
function writeLocalSharedImportMap_temp(content) {
|
|
384
402
|
var localSharedImportMapId = getLocalSharedImportMapPath_temp();
|
|
385
|
-
createFile(localSharedImportMapId +
|
|
403
|
+
createFile(localSharedImportMapId + '.js', '\n// Windows temporarily needs this file, https://github.com/module-federation/vite/issues/68\n' + content);
|
|
386
404
|
}
|
|
387
405
|
function createFile(filePath, content) {
|
|
388
406
|
var dir = path__default.dirname(filePath);
|
|
@@ -404,16 +422,16 @@ var nodeModulesDir = function findNodeModulesDir(startDir) {
|
|
|
404
422
|
}
|
|
405
423
|
currentDir = dirname(currentDir);
|
|
406
424
|
}
|
|
407
|
-
return
|
|
425
|
+
return '';
|
|
408
426
|
}();
|
|
409
|
-
var virtualPackageName =
|
|
427
|
+
var virtualPackageName = '__mf__virtual';
|
|
410
428
|
if (!existsSync(resolve(nodeModulesDir, virtualPackageName))) {
|
|
411
429
|
mkdirSync(resolve(nodeModulesDir, virtualPackageName));
|
|
412
430
|
}
|
|
413
|
-
writeFileSync(resolve(nodeModulesDir, virtualPackageName,
|
|
414
|
-
writeFileSync(resolve(nodeModulesDir, virtualPackageName,
|
|
431
|
+
writeFileSync(resolve(nodeModulesDir, virtualPackageName, 'empty.js'), '');
|
|
432
|
+
writeFileSync(resolve(nodeModulesDir, virtualPackageName, 'package.json'), JSON.stringify({
|
|
415
433
|
name: virtualPackageName,
|
|
416
|
-
main:
|
|
434
|
+
main: 'empty.js'
|
|
417
435
|
}));
|
|
418
436
|
var patternMap = {};
|
|
419
437
|
var cacheMap = {};
|
|
@@ -427,7 +445,7 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
427
445
|
tag = '__mf_v__';
|
|
428
446
|
}
|
|
429
447
|
if (suffix === void 0) {
|
|
430
|
-
suffix =
|
|
448
|
+
suffix = '';
|
|
431
449
|
}
|
|
432
450
|
this.name = void 0;
|
|
433
451
|
this.tag = void 0;
|
|
@@ -435,13 +453,13 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
435
453
|
this.inited = false;
|
|
436
454
|
this.name = name;
|
|
437
455
|
this.tag = tag;
|
|
438
|
-
this.suffix = suffix || ((_name$split$slice$pop = name.split(
|
|
456
|
+
this.suffix = suffix || ((_name$split$slice$pop = name.split('.').slice(1).pop()) == null ? void 0 : _name$split$slice$pop.replace(/(.)/, '.$1')) || '.js';
|
|
439
457
|
if (!cacheMap[this.tag]) cacheMap[this.tag] = {};
|
|
440
458
|
cacheMap[this.tag][this.name] = this;
|
|
441
459
|
}
|
|
442
460
|
VirtualModule.findModule = function findModule(tag, str) {
|
|
443
461
|
if (str === void 0) {
|
|
444
|
-
str =
|
|
462
|
+
str = '';
|
|
445
463
|
}
|
|
446
464
|
if (!patternMap[tag]) patternMap[tag] = new RegExp("(.*" + packageNameEncode(tag) + "(.+?)" + packageNameEncode(tag) + ".*)");
|
|
447
465
|
var moduleName = (str.match(patternMap[tag]) || [])[2];
|
|
@@ -470,7 +488,15 @@ var VirtualModule = /*#__PURE__*/function () {
|
|
|
470
488
|
return VirtualModule;
|
|
471
489
|
}();
|
|
472
490
|
|
|
473
|
-
var
|
|
491
|
+
var VIRTUAL_EXPOSES = 'virtual:mf-exposes';
|
|
492
|
+
function generateExposes() {
|
|
493
|
+
var options = getNormalizeModuleFederationOptions();
|
|
494
|
+
return "\n export default {\n " + Object.keys(options.exposes).map(function (key) {
|
|
495
|
+
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 ";
|
|
496
|
+
}).join(',') + "\n }\n ";
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
var virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
474
500
|
function writeRuntimeInitStatus() {
|
|
475
501
|
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 ");
|
|
476
502
|
}
|
|
@@ -479,7 +505,7 @@ var cacheRemoteMap = {};
|
|
|
479
505
|
var LOAD_REMOTE_TAG = '__loadRemote__';
|
|
480
506
|
function getRemoteVirtualModule(remote, command) {
|
|
481
507
|
if (!cacheRemoteMap[remote]) {
|
|
482
|
-
cacheRemoteMap[remote] = new VirtualModule(remote, LOAD_REMOTE_TAG,
|
|
508
|
+
cacheRemoteMap[remote] = new VirtualModule(remote, LOAD_REMOTE_TAG, '.js');
|
|
483
509
|
cacheRemoteMap[remote].writeSync(generateRemotes(remote, command));
|
|
484
510
|
}
|
|
485
511
|
var virtual = cacheRemoteMap[remote];
|
|
@@ -496,7 +522,7 @@ function getUsedRemotesMap() {
|
|
|
496
522
|
return usedRemotesMap;
|
|
497
523
|
}
|
|
498
524
|
function generateRemotes(id, command) {
|
|
499
|
-
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 !==
|
|
525
|
+
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 ";
|
|
500
526
|
}
|
|
501
527
|
|
|
502
528
|
/**
|
|
@@ -506,10 +532,10 @@ function generateRemotes(id, command) {
|
|
|
506
532
|
*/
|
|
507
533
|
// *** __prebuild__
|
|
508
534
|
var preBuildCacheMap = {};
|
|
509
|
-
var PREBUILD_TAG =
|
|
535
|
+
var PREBUILD_TAG = '__prebuild__';
|
|
510
536
|
function writePreBuildLibPath(pkg) {
|
|
511
537
|
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(pkg, PREBUILD_TAG);
|
|
512
|
-
preBuildCacheMap[pkg].writeSync(
|
|
538
|
+
preBuildCacheMap[pkg].writeSync('');
|
|
513
539
|
}
|
|
514
540
|
function getPreBuildLibImportId(pkg) {
|
|
515
541
|
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(pkg, PREBUILD_TAG);
|
|
@@ -517,15 +543,15 @@ function getPreBuildLibImportId(pkg) {
|
|
|
517
543
|
return importId;
|
|
518
544
|
}
|
|
519
545
|
// *** __loadShare__
|
|
520
|
-
var LOAD_SHARE_TAG =
|
|
546
|
+
var LOAD_SHARE_TAG = '__loadShare__';
|
|
521
547
|
var loadShareCacheMap = {};
|
|
522
548
|
function getLoadShareModulePath(pkg) {
|
|
523
|
-
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = new VirtualModule(pkg, LOAD_SHARE_TAG,
|
|
549
|
+
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = new VirtualModule(pkg, LOAD_SHARE_TAG, '.js');
|
|
524
550
|
var filepath = loadShareCacheMap[pkg].getPath();
|
|
525
551
|
return filepath;
|
|
526
552
|
}
|
|
527
553
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
528
|
-
loadShareCacheMap[pkg].writeSync("\n \n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !==
|
|
554
|
+
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 ");
|
|
529
555
|
}
|
|
530
556
|
|
|
531
557
|
var usedShares = new Set();
|
|
@@ -536,7 +562,7 @@ function addUsedShares(pkg) {
|
|
|
536
562
|
usedShares.add(pkg);
|
|
537
563
|
}
|
|
538
564
|
// *** Expose locally provided shared modules here
|
|
539
|
-
new VirtualModule(
|
|
565
|
+
new VirtualModule('localSharedImportMap');
|
|
540
566
|
function getLocalSharedImportMapPath() {
|
|
541
567
|
return getLocalSharedImportMapPath_temp();
|
|
542
568
|
// return localSharedImportMapModule.getPath()
|
|
@@ -554,7 +580,7 @@ function generateLocalSharedImportMap() {
|
|
|
554
580
|
var options = getNormalizeModuleFederationOptions();
|
|
555
581
|
return "\n const importMap = {\n " + Array.from(getUsedShares()).map(function (pkg) {
|
|
556
582
|
return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
|
|
557
|
-
}).join(
|
|
583
|
+
}).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
|
|
558
584
|
var shareItem = getNormalizeShareItem(key);
|
|
559
585
|
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 ";
|
|
560
586
|
}).join(',') + "\n }\n const usedRemotes = [" + Object.keys(getUsedRemotesMap()).map(function (key) {
|
|
@@ -569,17 +595,15 @@ function generateRemoteEntry(options) {
|
|
|
569
595
|
});
|
|
570
596
|
return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
|
|
571
597
|
return item[1];
|
|
572
|
-
}).join('\n') + "\n\n const
|
|
573
|
-
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 ";
|
|
574
|
-
}).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) {
|
|
598
|
+
}).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) {
|
|
575
599
|
return item[0] + "()";
|
|
576
|
-
}).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 ";
|
|
600
|
+
}).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 ";
|
|
577
601
|
}
|
|
578
602
|
/**
|
|
579
603
|
* Inject entry file, automatically init when used as host,
|
|
580
604
|
* and will not inject remoteEntry
|
|
581
605
|
*/
|
|
582
|
-
var hostAutoInitModule = new VirtualModule(
|
|
606
|
+
var hostAutoInitModule = new VirtualModule('hostAutoInit');
|
|
583
607
|
function writeHostAutoInit() {
|
|
584
608
|
hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
|
|
585
609
|
}
|
|
@@ -601,20 +625,19 @@ var Manifest = function Manifest() {
|
|
|
601
625
|
var name = mfOptions.name,
|
|
602
626
|
filename = mfOptions.filename,
|
|
603
627
|
manifestOptions = mfOptions.manifest;
|
|
604
|
-
var mfManifestName =
|
|
628
|
+
var mfManifestName = '';
|
|
605
629
|
if (manifestOptions === true) {
|
|
606
|
-
mfManifestName =
|
|
630
|
+
mfManifestName = 'mf-manifest.json';
|
|
607
631
|
}
|
|
608
|
-
if (typeof manifestOptions !==
|
|
609
|
-
mfManifestName = join((manifestOptions == null ? void 0 : manifestOptions.filePath) ||
|
|
632
|
+
if (typeof manifestOptions !== 'boolean') {
|
|
633
|
+
mfManifestName = join((manifestOptions == null ? void 0 : manifestOptions.filePath) || '', (manifestOptions == null ? void 0 : manifestOptions.fileName) || '');
|
|
610
634
|
}
|
|
611
635
|
var extensions;
|
|
612
636
|
var root;
|
|
613
637
|
var remoteEntryFile;
|
|
614
|
-
var publicPath;
|
|
615
638
|
var _command;
|
|
616
639
|
return [{
|
|
617
|
-
name: '
|
|
640
|
+
name: 'module-federation-manifest',
|
|
618
641
|
apply: 'serve',
|
|
619
642
|
configureServer: function configureServer(server) {
|
|
620
643
|
server.middlewares.use(function (req, res, next) {
|
|
@@ -622,10 +645,10 @@ var Manifest = function Manifest() {
|
|
|
622
645
|
next();
|
|
623
646
|
return;
|
|
624
647
|
}
|
|
625
|
-
if (req.url === mfManifestName.replace(/^\/?/,
|
|
648
|
+
if (req.url === mfManifestName.replace(/^\/?/, '/')) {
|
|
626
649
|
res.setHeader('Content-Type', 'application/json');
|
|
627
650
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
628
|
-
res.end(JSON.stringify({
|
|
651
|
+
res.end(JSON.stringify(_extends({}, generateMFManifest({}), {
|
|
629
652
|
id: name,
|
|
630
653
|
name: name,
|
|
631
654
|
metaData: {
|
|
@@ -650,70 +673,16 @@ var Manifest = function Manifest() {
|
|
|
650
673
|
name: ''
|
|
651
674
|
},
|
|
652
675
|
globalName: name,
|
|
653
|
-
pluginVersion: '0.2.5'
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
shared: Array.from(getUsedShares()).map(function (shareKey) {
|
|
657
|
-
var shareItem = getNormalizeShareItem(shareKey);
|
|
658
|
-
return {
|
|
659
|
-
id: name + ":" + shareKey,
|
|
660
|
-
name: shareKey,
|
|
661
|
-
version: shareItem.version,
|
|
662
|
-
requiredVersion: shareItem.shareConfig.requiredVersion,
|
|
663
|
-
assets: {
|
|
664
|
-
js: {
|
|
665
|
-
async: [],
|
|
666
|
-
sync: []
|
|
667
|
-
},
|
|
668
|
-
css: {
|
|
669
|
-
async: [],
|
|
670
|
-
sync: []
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
}),
|
|
675
|
-
remotes: function () {
|
|
676
|
-
var remotes = [];
|
|
677
|
-
var usedRemotesMap = getUsedRemotesMap();
|
|
678
|
-
Object.keys(usedRemotesMap).forEach(function (remoteKey) {
|
|
679
|
-
var usedModules = Array.from(usedRemotesMap[remoteKey]);
|
|
680
|
-
usedModules.forEach(function (moduleKey) {
|
|
681
|
-
remotes.push({
|
|
682
|
-
federationContainerName: mfOptions.remotes[remoteKey].entry,
|
|
683
|
-
moduleName: moduleKey.replace(remoteKey, '').replace('/', ''),
|
|
684
|
-
alias: remoteKey,
|
|
685
|
-
entry: '*'
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
});
|
|
689
|
-
return remotes;
|
|
690
|
-
}(),
|
|
691
|
-
exposes: Object.keys(mfOptions.exposes).map(function (key) {
|
|
692
|
-
var formatKey = key.replace('./', '');
|
|
693
|
-
return {
|
|
694
|
-
id: name + ':' + formatKey,
|
|
695
|
-
name: formatKey,
|
|
696
|
-
assets: {
|
|
697
|
-
js: {
|
|
698
|
-
async: [],
|
|
699
|
-
sync: []
|
|
700
|
-
},
|
|
701
|
-
css: {
|
|
702
|
-
sync: [],
|
|
703
|
-
async: []
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
path: key
|
|
707
|
-
};
|
|
708
|
-
})
|
|
709
|
-
}));
|
|
676
|
+
pluginVersion: '0.2.5'
|
|
677
|
+
}
|
|
678
|
+
})));
|
|
710
679
|
} else {
|
|
711
680
|
next();
|
|
712
681
|
}
|
|
713
682
|
});
|
|
714
683
|
}
|
|
715
684
|
}, {
|
|
716
|
-
name: '
|
|
685
|
+
name: 'module-federation-manifest',
|
|
717
686
|
enforce: 'post',
|
|
718
687
|
config: function config(_config, _ref) {
|
|
719
688
|
var command = _ref.command;
|
|
@@ -724,10 +693,10 @@ var Manifest = function Manifest() {
|
|
|
724
693
|
configResolved: function configResolved(config) {
|
|
725
694
|
root = config.root;
|
|
726
695
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
727
|
-
|
|
728
|
-
if (_command ===
|
|
696
|
+
config.base ? config.base.replace(/\/?$/, '/') : 'auto';
|
|
697
|
+
if (_command === 'serve') {
|
|
729
698
|
var origin = config.server.origin;
|
|
730
|
-
|
|
699
|
+
origin ? origin.replace(/\/?$/, '/') : 'auto';
|
|
731
700
|
}
|
|
732
701
|
},
|
|
733
702
|
generateBundle: function generateBundle(options, bundle) {
|
|
@@ -769,7 +738,7 @@ var Manifest = function Manifest() {
|
|
|
769
738
|
var _Object$entries$_i = _Object$entries[_i],
|
|
770
739
|
fileName = _Object$entries$_i[0],
|
|
771
740
|
fileData = _Object$entries$_i[1];
|
|
772
|
-
if (mfOptions.filename.replace(/[\[\]]/g,
|
|
741
|
+
if (mfOptions.filename.replace(/[\[\]]/g, '_') === fileData.name || fileData.name === 'remoteEntry') {
|
|
773
742
|
remoteEntryFile = fileData.fileName;
|
|
774
743
|
}
|
|
775
744
|
if (fileData.type === 'chunk') {
|
|
@@ -781,7 +750,7 @@ var Manifest = function Manifest() {
|
|
|
781
750
|
// 检查模块是否在 preloadModules 列表中
|
|
782
751
|
for (var _iterator2 = _createForOfIteratorHelperLoose(exposesModules), _step2; !(_step2 = _iterator2()).done;) {
|
|
783
752
|
var preloadModule = _step2.value;
|
|
784
|
-
var formatPreloadModule = preloadModule.replace(
|
|
753
|
+
var formatPreloadModule = preloadModule.replace('./', '');
|
|
785
754
|
if (isModuleMatched(relativeModulePath, formatPreloadModule)) {
|
|
786
755
|
var _filesContainingModul;
|
|
787
756
|
if (!filesContainingModules[preloadModule]) {
|
|
@@ -800,12 +769,11 @@ var Manifest = function Manifest() {
|
|
|
800
769
|
}
|
|
801
770
|
}
|
|
802
771
|
}
|
|
803
|
-
;
|
|
804
772
|
var fileToShareKey = {};
|
|
805
773
|
return Promise.resolve(Promise.all(Array.from(getUsedShares()).map(function (shareKey) {
|
|
806
774
|
try {
|
|
807
775
|
return Promise.resolve(_this.resolve(getPreBuildLibImportId(shareKey))).then(function (_this$resolve) {
|
|
808
|
-
var file = _this$resolve.id.split(
|
|
776
|
+
var file = _this$resolve.id.split('?')[0];
|
|
809
777
|
fileToShareKey[file] = shareKey;
|
|
810
778
|
});
|
|
811
779
|
} catch (e) {
|
|
@@ -845,7 +813,7 @@ var Manifest = function Manifest() {
|
|
|
845
813
|
_this.emitFile({
|
|
846
814
|
type: 'asset',
|
|
847
815
|
fileName: mfManifestName,
|
|
848
|
-
source: generateMFManifest(filesContainingModules)
|
|
816
|
+
source: JSON.stringify(generateMFManifest(filesContainingModules))
|
|
849
817
|
});
|
|
850
818
|
});
|
|
851
819
|
} catch (e) {
|
|
@@ -876,8 +844,7 @@ var Manifest = function Manifest() {
|
|
|
876
844
|
});
|
|
877
845
|
// @ts-ignore
|
|
878
846
|
var shared = Array.from(getUsedShares()).map(function (shareKey) {
|
|
879
|
-
|
|
880
|
-
if (!preloadMap[shareKey]) return;
|
|
847
|
+
var _preloadMap$shareKey, _preloadMap$shareKey2;
|
|
881
848
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
882
849
|
return {
|
|
883
850
|
id: name + ":" + shareKey,
|
|
@@ -886,8 +853,8 @@ var Manifest = function Manifest() {
|
|
|
886
853
|
requiredVersion: shareItem.shareConfig.requiredVersion,
|
|
887
854
|
assets: {
|
|
888
855
|
js: {
|
|
889
|
-
async: preloadMap[shareKey].async,
|
|
890
|
-
sync: preloadMap[shareKey].sync
|
|
856
|
+
async: (preloadMap == null || (_preloadMap$shareKey = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey.async) || [],
|
|
857
|
+
sync: (preloadMap == null || (_preloadMap$shareKey2 = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey2.sync) || []
|
|
891
858
|
},
|
|
892
859
|
css: {
|
|
893
860
|
async: [],
|
|
@@ -899,17 +866,17 @@ var Manifest = function Manifest() {
|
|
|
899
866
|
return item;
|
|
900
867
|
});
|
|
901
868
|
var exposes = Object.keys(options.exposes).map(function (key) {
|
|
869
|
+
var _preloadMap$sourceFil, _preloadMap$sourceFil2;
|
|
902
870
|
// assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
|
|
903
871
|
var formatKey = key.replace('./', '');
|
|
904
872
|
var sourceFile = options.exposes[key]["import"];
|
|
905
|
-
if (!preloadMap[sourceFile]) return;
|
|
906
873
|
return {
|
|
907
874
|
id: name + ':' + formatKey,
|
|
908
875
|
name: formatKey,
|
|
909
876
|
assets: {
|
|
910
877
|
js: {
|
|
911
|
-
async: preloadMap[sourceFile].async,
|
|
912
|
-
sync: preloadMap[sourceFile].sync
|
|
878
|
+
async: (preloadMap == null || (_preloadMap$sourceFil = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil.async) || [],
|
|
879
|
+
sync: (preloadMap == null || (_preloadMap$sourceFil2 = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil2.sync) || []
|
|
913
880
|
},
|
|
914
881
|
css: {
|
|
915
882
|
sync: [],
|
|
@@ -940,14 +907,13 @@ var Manifest = function Manifest() {
|
|
|
940
907
|
// "api": "@mf-types.d.ts"
|
|
941
908
|
},
|
|
942
909
|
globalName: name,
|
|
943
|
-
pluginVersion: '0.2.5'
|
|
944
|
-
publicPath: publicPath
|
|
910
|
+
pluginVersion: '0.2.5'
|
|
945
911
|
},
|
|
946
912
|
shared: shared,
|
|
947
913
|
remotes: remotes,
|
|
948
914
|
exposes: exposes
|
|
949
915
|
};
|
|
950
|
-
return
|
|
916
|
+
return result;
|
|
951
917
|
}
|
|
952
918
|
};
|
|
953
919
|
|
|
@@ -956,20 +922,21 @@ var _resolve,
|
|
|
956
922
|
_resolve = resolve;
|
|
957
923
|
});
|
|
958
924
|
var parsePromise = promise;
|
|
925
|
+
var exposesParseEnd = false;
|
|
959
926
|
var parseStartSet = new Set();
|
|
960
927
|
var parseEndSet = new Set();
|
|
961
928
|
function pluginModuleParseEnd (excludeFn) {
|
|
962
929
|
return [{
|
|
963
|
-
name:
|
|
964
|
-
apply:
|
|
930
|
+
name: '_',
|
|
931
|
+
apply: 'serve',
|
|
965
932
|
config: function config() {
|
|
966
933
|
// No waiting in development mode
|
|
967
934
|
_resolve(1);
|
|
968
935
|
}
|
|
969
936
|
}, {
|
|
970
|
-
enforce:
|
|
971
|
-
name:
|
|
972
|
-
apply:
|
|
937
|
+
enforce: 'pre',
|
|
938
|
+
name: 'parseStart',
|
|
939
|
+
apply: 'build',
|
|
973
940
|
load: function load(id) {
|
|
974
941
|
if (excludeFn(id)) {
|
|
975
942
|
return;
|
|
@@ -977,16 +944,20 @@ function pluginModuleParseEnd (excludeFn) {
|
|
|
977
944
|
parseStartSet.add(id);
|
|
978
945
|
}
|
|
979
946
|
}, {
|
|
980
|
-
enforce:
|
|
981
|
-
name:
|
|
982
|
-
apply:
|
|
947
|
+
enforce: 'post',
|
|
948
|
+
name: 'parseEnd',
|
|
949
|
+
apply: 'build',
|
|
983
950
|
moduleParsed: function moduleParsed(module) {
|
|
984
951
|
var id = module.id;
|
|
985
952
|
if (excludeFn(id)) {
|
|
986
953
|
return;
|
|
987
954
|
}
|
|
955
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
956
|
+
// 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.
|
|
957
|
+
exposesParseEnd = true;
|
|
958
|
+
}
|
|
988
959
|
parseEndSet.add(id);
|
|
989
|
-
if (parseStartSet.size === parseEndSet.size) {
|
|
960
|
+
if (exposesParseEnd && parseStartSet.size === parseEndSet.size) {
|
|
990
961
|
_resolve(1);
|
|
991
962
|
}
|
|
992
963
|
}
|
|
@@ -1002,6 +973,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1002
973
|
if (id === REMOTE_ENTRY_ID) {
|
|
1003
974
|
return REMOTE_ENTRY_ID;
|
|
1004
975
|
}
|
|
976
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
977
|
+
return VIRTUAL_EXPOSES;
|
|
978
|
+
}
|
|
1005
979
|
},
|
|
1006
980
|
load: function load(id) {
|
|
1007
981
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1009,6 +983,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1009
983
|
return generateRemoteEntry(getNormalizeModuleFederationOptions());
|
|
1010
984
|
});
|
|
1011
985
|
}
|
|
986
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
987
|
+
return generateExposes();
|
|
988
|
+
}
|
|
1012
989
|
},
|
|
1013
990
|
transform: function transform(code, id) {
|
|
1014
991
|
try {
|
|
@@ -1018,6 +995,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1018
995
|
return generateRemoteEntry(getNormalizeModuleFederationOptions());
|
|
1019
996
|
}));
|
|
1020
997
|
}
|
|
998
|
+
if (id === VIRTUAL_EXPOSES) {
|
|
999
|
+
return Promise.resolve(generateExposes());
|
|
1000
|
+
}
|
|
1021
1001
|
return Promise.resolve();
|
|
1022
1002
|
} catch (e) {
|
|
1023
1003
|
return Promise.reject(e);
|
|
@@ -1030,14 +1010,14 @@ createFilter();
|
|
|
1030
1010
|
function pluginProxyRemotes (options) {
|
|
1031
1011
|
var remotes = options.remotes;
|
|
1032
1012
|
return {
|
|
1033
|
-
name:
|
|
1013
|
+
name: 'proxyRemotes',
|
|
1034
1014
|
config: function config(_config, _ref) {
|
|
1035
1015
|
var _command = _ref.command;
|
|
1036
1016
|
Object.keys(remotes).forEach(function (key) {
|
|
1037
1017
|
var remote = remotes[key];
|
|
1038
1018
|
_config.resolve.alias.push({
|
|
1039
1019
|
find: new RegExp("^(" + remote.name + "(/.*|$))"),
|
|
1040
|
-
replacement:
|
|
1020
|
+
replacement: '$1',
|
|
1041
1021
|
customResolver: function customResolver(source) {
|
|
1042
1022
|
var remoteModule = getRemoteVirtualModule(source, _command);
|
|
1043
1023
|
addUsedRemote(remote.name, source);
|
|
@@ -1091,8 +1071,8 @@ function proxySharedModule(options) {
|
|
|
1091
1071
|
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
1092
1072
|
var _config;
|
|
1093
1073
|
return [{
|
|
1094
|
-
name:
|
|
1095
|
-
enforce:
|
|
1074
|
+
name: 'generateLocalSharedImportMap',
|
|
1075
|
+
enforce: 'post',
|
|
1096
1076
|
load: function load(id) {
|
|
1097
1077
|
if (id.includes(getLocalSharedImportMapPath())) {
|
|
1098
1078
|
return parsePromise.then(function (_) {
|
|
@@ -1117,11 +1097,11 @@ function proxySharedModule(options) {
|
|
|
1117
1097
|
var _config2$resolve$alia, _config2$resolve$alia2;
|
|
1118
1098
|
var command = _ref.command;
|
|
1119
1099
|
(_config2$resolve$alia = _config2.resolve.alias).push.apply(_config2$resolve$alia, Object.keys(shared).map(function (key) {
|
|
1120
|
-
var pattern = key.endsWith(
|
|
1100
|
+
var pattern = key.endsWith('/') ? "(^" + key.replace(/\/$/, '') + "(/.+)?$)" : "(^" + key + "$)";
|
|
1121
1101
|
return {
|
|
1122
1102
|
// Intercept all shared requests and proxy them to loadShare
|
|
1123
1103
|
find: new RegExp(pattern),
|
|
1124
|
-
replacement:
|
|
1104
|
+
replacement: '$1',
|
|
1125
1105
|
customResolver: function customResolver(source, importer) {
|
|
1126
1106
|
if (/\.css$/.test(source)) return;
|
|
1127
1107
|
var loadSharePath = getLoadShareModulePath(source);
|
|
@@ -1135,7 +1115,7 @@ function proxySharedModule(options) {
|
|
|
1135
1115
|
}));
|
|
1136
1116
|
var savePrebuild = new PromiseStore();
|
|
1137
1117
|
(_config2$resolve$alia2 = _config2.resolve.alias).push.apply(_config2$resolve$alia2, Object.keys(shared).map(function (key) {
|
|
1138
|
-
return command ===
|
|
1118
|
+
return command === 'build' ? {
|
|
1139
1119
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1140
1120
|
replacement: function replacement($1) {
|
|
1141
1121
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, $1).name;
|
|
@@ -1143,7 +1123,7 @@ function proxySharedModule(options) {
|
|
|
1143
1123
|
}
|
|
1144
1124
|
} : {
|
|
1145
1125
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1146
|
-
replacement:
|
|
1126
|
+
replacement: '$1',
|
|
1147
1127
|
customResolver: function customResolver(source, importer) {
|
|
1148
1128
|
try {
|
|
1149
1129
|
var _this = this;
|
|
@@ -1169,8 +1149,8 @@ function proxySharedModule(options) {
|
|
|
1169
1149
|
}));
|
|
1170
1150
|
}
|
|
1171
1151
|
}, {
|
|
1172
|
-
name:
|
|
1173
|
-
apply:
|
|
1152
|
+
name: 'watchLocalSharedImportMap',
|
|
1153
|
+
apply: 'serve',
|
|
1174
1154
|
config: function config(_config3) {
|
|
1175
1155
|
_config3.optimizeDeps = defu(_config3.optimizeDeps, {
|
|
1176
1156
|
exclude: [getLocalSharedImportMapPath()]
|
|
@@ -1227,7 +1207,7 @@ function federation(mfUserOptions) {
|
|
|
1227
1207
|
var name = options.name,
|
|
1228
1208
|
shared = options.shared,
|
|
1229
1209
|
filename = options.filename;
|
|
1230
|
-
if (!name) throw new Error(
|
|
1210
|
+
if (!name) throw new Error('name is required');
|
|
1231
1211
|
return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin].concat(addEntry({
|
|
1232
1212
|
entryName: 'remoteEntry',
|
|
1233
1213
|
entryPath: REMOTE_ENTRY_ID,
|
|
@@ -1235,6 +1215,9 @@ function federation(mfUserOptions) {
|
|
|
1235
1215
|
}), addEntry({
|
|
1236
1216
|
entryName: 'hostInit',
|
|
1237
1217
|
entryPath: getHostAutoInitPath()
|
|
1218
|
+
}), addEntry({
|
|
1219
|
+
entryName: 'virtualExposes',
|
|
1220
|
+
entryPath: VIRTUAL_EXPOSES
|
|
1238
1221
|
}), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
|
|
1239
1222
|
return id.includes(getHostAutoInitImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
|
|
1240
1223
|
}), proxySharedModule({
|
|
@@ -1244,6 +1227,7 @@ function federation(mfUserOptions) {
|
|
|
1244
1227
|
enforce: 'post',
|
|
1245
1228
|
config: function config(_config, _ref) {
|
|
1246
1229
|
var _config$optimizeDeps;
|
|
1230
|
+
// TODO: singleton
|
|
1247
1231
|
_config.resolve.alias.push({
|
|
1248
1232
|
find: '@module-federation/runtime',
|
|
1249
1233
|
replacement: require.resolve('@module-federation/runtime')
|