@module-federation/vite 1.1.5 → 1.1.7
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 +6 -0
- package/lib/index.cjs +27 -4
- package/lib/index.esm.js +27 -4
- package/lib/index.modern.js +45 -5
- package/lib/index.umd.js +27 -4
- package/lib/utils/normalizeModuleFederationOptions.d.ts +2 -2
- package/package.json +22 -20
package/README.md
CHANGED
|
@@ -67,6 +67,9 @@ export default defineConfig({
|
|
|
67
67
|
shared: ["vue"],
|
|
68
68
|
}),
|
|
69
69
|
],
|
|
70
|
+
server: {
|
|
71
|
+
origin: "http://localhost:{Your port}"
|
|
72
|
+
},
|
|
70
73
|
// Do you need to support build targets lower than chrome89?
|
|
71
74
|
// You can use 'vite-plugin-top-level-await' plugin for that.
|
|
72
75
|
build: {
|
|
@@ -106,6 +109,9 @@ export default defineConfig({
|
|
|
106
109
|
shared: ["vue"],
|
|
107
110
|
}),
|
|
108
111
|
],
|
|
112
|
+
server: {
|
|
113
|
+
origin: "http://localhost:{Your port}"
|
|
114
|
+
},
|
|
109
115
|
// Do you need to support build targets lower than chrome89?
|
|
110
116
|
// You can use 'vite-plugin-top-level-await' plugin for that.
|
|
111
117
|
build: {
|
package/lib/index.cjs
CHANGED
|
@@ -71,6 +71,7 @@ var addEntry = function addEntry(_ref) {
|
|
|
71
71
|
});
|
|
72
72
|
},
|
|
73
73
|
transformIndexHtml: function transformIndexHtml(c) {
|
|
74
|
+
if (inject !== 'html') return;
|
|
74
75
|
return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
|
|
75
76
|
}
|
|
76
77
|
}, {
|
|
@@ -401,7 +402,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
401
402
|
shareScope: options.shareScope || 'default',
|
|
402
403
|
shared: normalizeShared(options.shared),
|
|
403
404
|
runtimePlugins: options.runtimePlugins || [],
|
|
404
|
-
implementation: options.implementation,
|
|
405
|
+
implementation: options.implementation || require.resolve('@module-federation/runtime'),
|
|
405
406
|
manifest: normalizeManifest(options.manifest),
|
|
406
407
|
dev: options.dev,
|
|
407
408
|
dts: options.dts,
|
|
@@ -642,9 +643,9 @@ function generateRemoteEntry(options) {
|
|
|
642
643
|
});
|
|
643
644
|
return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
|
|
644
645
|
return item[1];
|
|
645
|
-
}).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:
|
|
646
|
+
}).join('\n') + "\n import exposesMap from \"" + VIRTUAL_EXPOSES + "\"\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n const initTokens = {}\n const shareScopeName = " + JSON.stringify(options.shareScope) + "\n const mfName = " + JSON.stringify(options.name) + "\n async function init(shared = {}, initScope = []) {\n const initRes = runtimeInit({\n name: mfName,\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
|
|
646
647
|
return item[0] + "()";
|
|
647
|
-
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {strategy: '" + options.shareStrategy + "'}));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
648
|
+
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n // handling circular init calls\n var initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: mfName };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {\n strategy: '" + options.shareStrategy + "',\n from: \"build\",\n initScope\n }));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
648
649
|
}
|
|
649
650
|
/**
|
|
650
651
|
* Inject entry file, automatically init when used as host,
|
|
@@ -1025,9 +1026,17 @@ function pluginModuleParseEnd (excludeFn) {
|
|
|
1025
1026
|
|
|
1026
1027
|
var filter = pluginutils.createFilter();
|
|
1027
1028
|
function pluginProxyRemoteEntry () {
|
|
1029
|
+
var viteConfig, _command;
|
|
1028
1030
|
return {
|
|
1029
1031
|
name: 'proxyRemoteEntry',
|
|
1030
1032
|
enforce: 'post',
|
|
1033
|
+
configResolved: function configResolved(config) {
|
|
1034
|
+
viteConfig = config;
|
|
1035
|
+
},
|
|
1036
|
+
config: function config(_config, _ref) {
|
|
1037
|
+
var command = _ref.command;
|
|
1038
|
+
_command = command;
|
|
1039
|
+
},
|
|
1031
1040
|
resolveId: function resolveId(id) {
|
|
1032
1041
|
if (id === REMOTE_ENTRY_ID) {
|
|
1033
1042
|
return REMOTE_ENTRY_ID;
|
|
@@ -1035,6 +1044,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1035
1044
|
if (id === VIRTUAL_EXPOSES) {
|
|
1036
1045
|
return VIRTUAL_EXPOSES;
|
|
1037
1046
|
}
|
|
1047
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1048
|
+
return id;
|
|
1049
|
+
}
|
|
1038
1050
|
},
|
|
1039
1051
|
load: function load(id) {
|
|
1040
1052
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1045,6 +1057,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1045
1057
|
if (id === VIRTUAL_EXPOSES) {
|
|
1046
1058
|
return generateExposes();
|
|
1047
1059
|
}
|
|
1060
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1061
|
+
return id;
|
|
1062
|
+
}
|
|
1048
1063
|
},
|
|
1049
1064
|
transform: function transform(code, id) {
|
|
1050
1065
|
try {
|
|
@@ -1057,6 +1072,14 @@ function pluginProxyRemoteEntry () {
|
|
|
1057
1072
|
if (id === VIRTUAL_EXPOSES) {
|
|
1058
1073
|
return Promise.resolve(generateExposes());
|
|
1059
1074
|
}
|
|
1075
|
+
if (id.includes(getHostAutoInitPath())) {
|
|
1076
|
+
var options = getNormalizeModuleFederationOptions();
|
|
1077
|
+
if (_command === 'serve') {
|
|
1078
|
+
var _viteConfig$server;
|
|
1079
|
+
return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
|
|
1080
|
+
}
|
|
1081
|
+
return Promise.resolve(code);
|
|
1082
|
+
}
|
|
1060
1083
|
return Promise.resolve();
|
|
1061
1084
|
} catch (e) {
|
|
1062
1085
|
return Promise.reject(e);
|
|
@@ -1293,7 +1316,7 @@ function federation(mfUserOptions) {
|
|
|
1293
1316
|
// TODO: singleton
|
|
1294
1317
|
_config.resolve.alias.push({
|
|
1295
1318
|
find: '@module-federation/runtime',
|
|
1296
|
-
replacement:
|
|
1319
|
+
replacement: options.implementation
|
|
1297
1320
|
});
|
|
1298
1321
|
(_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
|
|
1299
1322
|
(_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
|
package/lib/index.esm.js
CHANGED
|
@@ -48,6 +48,7 @@ var addEntry = function addEntry(_ref) {
|
|
|
48
48
|
});
|
|
49
49
|
},
|
|
50
50
|
transformIndexHtml: function transformIndexHtml(c) {
|
|
51
|
+
if (inject !== 'html') return;
|
|
51
52
|
return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
|
|
52
53
|
}
|
|
53
54
|
}, {
|
|
@@ -378,7 +379,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
378
379
|
shareScope: options.shareScope || 'default',
|
|
379
380
|
shared: normalizeShared(options.shared),
|
|
380
381
|
runtimePlugins: options.runtimePlugins || [],
|
|
381
|
-
implementation: options.implementation,
|
|
382
|
+
implementation: options.implementation || require.resolve('@module-federation/runtime'),
|
|
382
383
|
manifest: normalizeManifest(options.manifest),
|
|
383
384
|
dev: options.dev,
|
|
384
385
|
dts: options.dts,
|
|
@@ -619,9 +620,9 @@ function generateRemoteEntry(options) {
|
|
|
619
620
|
});
|
|
620
621
|
return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
|
|
621
622
|
return item[1];
|
|
622
|
-
}).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:
|
|
623
|
+
}).join('\n') + "\n import exposesMap from \"" + VIRTUAL_EXPOSES + "\"\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n const initTokens = {}\n const shareScopeName = " + JSON.stringify(options.shareScope) + "\n const mfName = " + JSON.stringify(options.name) + "\n async function init(shared = {}, initScope = []) {\n const initRes = runtimeInit({\n name: mfName,\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
|
|
623
624
|
return item[0] + "()";
|
|
624
|
-
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {strategy: '" + options.shareStrategy + "'}));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
625
|
+
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n // handling circular init calls\n var initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: mfName };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {\n strategy: '" + options.shareStrategy + "',\n from: \"build\",\n initScope\n }));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
625
626
|
}
|
|
626
627
|
/**
|
|
627
628
|
* Inject entry file, automatically init when used as host,
|
|
@@ -1002,9 +1003,17 @@ function pluginModuleParseEnd (excludeFn) {
|
|
|
1002
1003
|
|
|
1003
1004
|
var filter = createFilter();
|
|
1004
1005
|
function pluginProxyRemoteEntry () {
|
|
1006
|
+
var viteConfig, _command;
|
|
1005
1007
|
return {
|
|
1006
1008
|
name: 'proxyRemoteEntry',
|
|
1007
1009
|
enforce: 'post',
|
|
1010
|
+
configResolved: function configResolved(config) {
|
|
1011
|
+
viteConfig = config;
|
|
1012
|
+
},
|
|
1013
|
+
config: function config(_config, _ref) {
|
|
1014
|
+
var command = _ref.command;
|
|
1015
|
+
_command = command;
|
|
1016
|
+
},
|
|
1008
1017
|
resolveId: function resolveId(id) {
|
|
1009
1018
|
if (id === REMOTE_ENTRY_ID) {
|
|
1010
1019
|
return REMOTE_ENTRY_ID;
|
|
@@ -1012,6 +1021,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1012
1021
|
if (id === VIRTUAL_EXPOSES) {
|
|
1013
1022
|
return VIRTUAL_EXPOSES;
|
|
1014
1023
|
}
|
|
1024
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1025
|
+
return id;
|
|
1026
|
+
}
|
|
1015
1027
|
},
|
|
1016
1028
|
load: function load(id) {
|
|
1017
1029
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1022,6 +1034,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1022
1034
|
if (id === VIRTUAL_EXPOSES) {
|
|
1023
1035
|
return generateExposes();
|
|
1024
1036
|
}
|
|
1037
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1038
|
+
return id;
|
|
1039
|
+
}
|
|
1025
1040
|
},
|
|
1026
1041
|
transform: function transform(code, id) {
|
|
1027
1042
|
try {
|
|
@@ -1034,6 +1049,14 @@ function pluginProxyRemoteEntry () {
|
|
|
1034
1049
|
if (id === VIRTUAL_EXPOSES) {
|
|
1035
1050
|
return Promise.resolve(generateExposes());
|
|
1036
1051
|
}
|
|
1052
|
+
if (id.includes(getHostAutoInitPath())) {
|
|
1053
|
+
var options = getNormalizeModuleFederationOptions();
|
|
1054
|
+
if (_command === 'serve') {
|
|
1055
|
+
var _viteConfig$server;
|
|
1056
|
+
return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
|
|
1057
|
+
}
|
|
1058
|
+
return Promise.resolve(code);
|
|
1059
|
+
}
|
|
1037
1060
|
return Promise.resolve();
|
|
1038
1061
|
} catch (e) {
|
|
1039
1062
|
return Promise.reject(e);
|
|
@@ -1270,7 +1293,7 @@ function federation(mfUserOptions) {
|
|
|
1270
1293
|
// TODO: singleton
|
|
1271
1294
|
_config.resolve.alias.push({
|
|
1272
1295
|
find: '@module-federation/runtime',
|
|
1273
|
-
replacement:
|
|
1296
|
+
replacement: options.implementation
|
|
1274
1297
|
});
|
|
1275
1298
|
(_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
|
|
1276
1299
|
(_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
|
package/lib/index.modern.js
CHANGED
|
@@ -51,6 +51,7 @@ const addEntry = ({
|
|
|
51
51
|
});
|
|
52
52
|
},
|
|
53
53
|
transformIndexHtml(c) {
|
|
54
|
+
if (_inject !== 'html') return;
|
|
54
55
|
return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/'))}></script>`);
|
|
55
56
|
}
|
|
56
57
|
}, {
|
|
@@ -352,7 +353,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
352
353
|
shareScope: options.shareScope || 'default',
|
|
353
354
|
shared: normalizeShared(options.shared),
|
|
354
355
|
runtimePlugins: options.runtimePlugins || [],
|
|
355
|
-
implementation: options.implementation,
|
|
356
|
+
implementation: options.implementation || require.resolve('@module-federation/runtime'),
|
|
356
357
|
manifest: normalizeManifest(options.manifest),
|
|
357
358
|
dev: options.dev,
|
|
358
359
|
dts: options.dts,
|
|
@@ -681,17 +682,30 @@ function generateRemoteEntry(options) {
|
|
|
681
682
|
import {
|
|
682
683
|
initResolve
|
|
683
684
|
} from "${virtualRuntimeInitStatus.getImportId()}"
|
|
684
|
-
|
|
685
|
+
const initTokens = {}
|
|
686
|
+
const shareScopeName = ${JSON.stringify(options.shareScope)}
|
|
687
|
+
const mfName = ${JSON.stringify(options.name)}
|
|
688
|
+
async function init(shared = {}, initScope = []) {
|
|
685
689
|
const initRes = runtimeInit({
|
|
686
|
-
name:
|
|
690
|
+
name: mfName,
|
|
687
691
|
remotes: usedRemotes,
|
|
688
692
|
shared: usedShared,
|
|
689
693
|
plugins: [${pluginImportNames.map(item => `${item[0]}()`).join(', ')}],
|
|
690
694
|
${options.shareStrategy ? `shareStrategy: '${options.shareStrategy}'` : ''}
|
|
691
695
|
});
|
|
696
|
+
// handling circular init calls
|
|
697
|
+
var initToken = initTokens[shareScopeName];
|
|
698
|
+
if (!initToken)
|
|
699
|
+
initToken = initTokens[shareScopeName] = { from: mfName };
|
|
700
|
+
if (initScope.indexOf(initToken) >= 0) return;
|
|
701
|
+
initScope.push(initToken);
|
|
692
702
|
initRes.initShareScopeMap('${options.shareScope}', shared);
|
|
693
703
|
try {
|
|
694
|
-
await Promise.all(await initRes.initializeSharing('${options.shareScope}', {
|
|
704
|
+
await Promise.all(await initRes.initializeSharing('${options.shareScope}', {
|
|
705
|
+
strategy: '${options.shareStrategy}',
|
|
706
|
+
from: "build",
|
|
707
|
+
initScope
|
|
708
|
+
}));
|
|
695
709
|
} catch (e) {
|
|
696
710
|
console.error(e)
|
|
697
711
|
}
|
|
@@ -1066,9 +1080,18 @@ function pluginModuleParseEnd (excludeFn) {
|
|
|
1066
1080
|
|
|
1067
1081
|
const filter = createFilter();
|
|
1068
1082
|
function pluginProxyRemoteEntry () {
|
|
1083
|
+
let viteConfig, _command;
|
|
1069
1084
|
return {
|
|
1070
1085
|
name: 'proxyRemoteEntry',
|
|
1071
1086
|
enforce: 'post',
|
|
1087
|
+
configResolved(config) {
|
|
1088
|
+
viteConfig = config;
|
|
1089
|
+
},
|
|
1090
|
+
config(config, {
|
|
1091
|
+
command
|
|
1092
|
+
}) {
|
|
1093
|
+
_command = command;
|
|
1094
|
+
},
|
|
1072
1095
|
resolveId(id) {
|
|
1073
1096
|
if (id === REMOTE_ENTRY_ID) {
|
|
1074
1097
|
return REMOTE_ENTRY_ID;
|
|
@@ -1076,6 +1099,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1076
1099
|
if (id === VIRTUAL_EXPOSES) {
|
|
1077
1100
|
return VIRTUAL_EXPOSES;
|
|
1078
1101
|
}
|
|
1102
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1103
|
+
return id;
|
|
1104
|
+
}
|
|
1079
1105
|
},
|
|
1080
1106
|
load(id) {
|
|
1081
1107
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1084,6 +1110,9 @@ function pluginProxyRemoteEntry () {
|
|
|
1084
1110
|
if (id === VIRTUAL_EXPOSES) {
|
|
1085
1111
|
return generateExposes();
|
|
1086
1112
|
}
|
|
1113
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1114
|
+
return id;
|
|
1115
|
+
}
|
|
1087
1116
|
},
|
|
1088
1117
|
async transform(code, id) {
|
|
1089
1118
|
if (!filter(id)) return;
|
|
@@ -1093,6 +1122,17 @@ function pluginProxyRemoteEntry () {
|
|
|
1093
1122
|
if (id === VIRTUAL_EXPOSES) {
|
|
1094
1123
|
return generateExposes();
|
|
1095
1124
|
}
|
|
1125
|
+
if (id.includes(getHostAutoInitPath())) {
|
|
1126
|
+
const options = getNormalizeModuleFederationOptions();
|
|
1127
|
+
if (_command === 'serve') {
|
|
1128
|
+
var _viteConfig$server;
|
|
1129
|
+
return `
|
|
1130
|
+
const {init} = await import("//localhost:${(_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port}${viteConfig.base + options.filename}")
|
|
1131
|
+
init()
|
|
1132
|
+
`;
|
|
1133
|
+
}
|
|
1134
|
+
return code;
|
|
1135
|
+
}
|
|
1096
1136
|
}
|
|
1097
1137
|
};
|
|
1098
1138
|
}
|
|
@@ -1322,7 +1362,7 @@ function federation(mfUserOptions) {
|
|
|
1322
1362
|
// TODO: singleton
|
|
1323
1363
|
config.resolve.alias.push({
|
|
1324
1364
|
find: '@module-federation/runtime',
|
|
1325
|
-
replacement:
|
|
1365
|
+
replacement: options.implementation
|
|
1326
1366
|
});
|
|
1327
1367
|
(_config$optimizeDeps = config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
|
|
1328
1368
|
(_config$optimizeDeps2 = config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
|
package/lib/index.umd.js
CHANGED
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
});
|
|
70
70
|
},
|
|
71
71
|
transformIndexHtml: function transformIndexHtml(c) {
|
|
72
|
+
if (inject !== 'html') return;
|
|
72
73
|
return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
|
|
73
74
|
}
|
|
74
75
|
}, {
|
|
@@ -399,7 +400,7 @@
|
|
|
399
400
|
shareScope: options.shareScope || 'default',
|
|
400
401
|
shared: normalizeShared(options.shared),
|
|
401
402
|
runtimePlugins: options.runtimePlugins || [],
|
|
402
|
-
implementation: options.implementation,
|
|
403
|
+
implementation: options.implementation || require.resolve('@module-federation/runtime'),
|
|
403
404
|
manifest: normalizeManifest(options.manifest),
|
|
404
405
|
dev: options.dev,
|
|
405
406
|
dts: options.dts,
|
|
@@ -640,9 +641,9 @@
|
|
|
640
641
|
});
|
|
641
642
|
return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
|
|
642
643
|
return item[1];
|
|
643
|
-
}).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:
|
|
644
|
+
}).join('\n') + "\n import exposesMap from \"" + VIRTUAL_EXPOSES + "\"\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n const initTokens = {}\n const shareScopeName = " + JSON.stringify(options.shareScope) + "\n const mfName = " + JSON.stringify(options.name) + "\n async function init(shared = {}, initScope = []) {\n const initRes = runtimeInit({\n name: mfName,\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
|
|
644
645
|
return item[0] + "()";
|
|
645
|
-
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {strategy: '" + options.shareStrategy + "'}));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
646
|
+
}).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n // handling circular init calls\n var initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: mfName };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {\n strategy: '" + options.shareStrategy + "',\n from: \"build\",\n initScope\n }));\n } catch (e) {\n console.error(e)\n }\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 ";
|
|
646
647
|
}
|
|
647
648
|
/**
|
|
648
649
|
* Inject entry file, automatically init when used as host,
|
|
@@ -1023,9 +1024,17 @@
|
|
|
1023
1024
|
|
|
1024
1025
|
var filter = pluginutils.createFilter();
|
|
1025
1026
|
function pluginProxyRemoteEntry () {
|
|
1027
|
+
var viteConfig, _command;
|
|
1026
1028
|
return {
|
|
1027
1029
|
name: 'proxyRemoteEntry',
|
|
1028
1030
|
enforce: 'post',
|
|
1031
|
+
configResolved: function configResolved(config) {
|
|
1032
|
+
viteConfig = config;
|
|
1033
|
+
},
|
|
1034
|
+
config: function config(_config, _ref) {
|
|
1035
|
+
var command = _ref.command;
|
|
1036
|
+
_command = command;
|
|
1037
|
+
},
|
|
1029
1038
|
resolveId: function resolveId(id) {
|
|
1030
1039
|
if (id === REMOTE_ENTRY_ID) {
|
|
1031
1040
|
return REMOTE_ENTRY_ID;
|
|
@@ -1033,6 +1042,9 @@
|
|
|
1033
1042
|
if (id === VIRTUAL_EXPOSES) {
|
|
1034
1043
|
return VIRTUAL_EXPOSES;
|
|
1035
1044
|
}
|
|
1045
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1046
|
+
return id;
|
|
1047
|
+
}
|
|
1036
1048
|
},
|
|
1037
1049
|
load: function load(id) {
|
|
1038
1050
|
if (id === REMOTE_ENTRY_ID) {
|
|
@@ -1043,6 +1055,9 @@
|
|
|
1043
1055
|
if (id === VIRTUAL_EXPOSES) {
|
|
1044
1056
|
return generateExposes();
|
|
1045
1057
|
}
|
|
1058
|
+
if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
|
|
1059
|
+
return id;
|
|
1060
|
+
}
|
|
1046
1061
|
},
|
|
1047
1062
|
transform: function transform(code, id) {
|
|
1048
1063
|
try {
|
|
@@ -1055,6 +1070,14 @@
|
|
|
1055
1070
|
if (id === VIRTUAL_EXPOSES) {
|
|
1056
1071
|
return Promise.resolve(generateExposes());
|
|
1057
1072
|
}
|
|
1073
|
+
if (id.includes(getHostAutoInitPath())) {
|
|
1074
|
+
var options = getNormalizeModuleFederationOptions();
|
|
1075
|
+
if (_command === 'serve') {
|
|
1076
|
+
var _viteConfig$server;
|
|
1077
|
+
return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
|
|
1078
|
+
}
|
|
1079
|
+
return Promise.resolve(code);
|
|
1080
|
+
}
|
|
1058
1081
|
return Promise.resolve();
|
|
1059
1082
|
} catch (e) {
|
|
1060
1083
|
return Promise.reject(e);
|
|
@@ -1291,7 +1314,7 @@
|
|
|
1291
1314
|
// TODO: singleton
|
|
1292
1315
|
_config.resolve.alias.push({
|
|
1293
1316
|
find: '@module-federation/runtime',
|
|
1294
|
-
replacement:
|
|
1317
|
+
replacement: options.implementation
|
|
1295
1318
|
});
|
|
1296
1319
|
(_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
|
|
1297
1320
|
(_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
|
|
@@ -46,7 +46,7 @@ export type ModuleFederationOptions = {
|
|
|
46
46
|
}> | undefined;
|
|
47
47
|
runtimePlugins?: string[];
|
|
48
48
|
getPublicPath?: string;
|
|
49
|
-
implementation?:
|
|
49
|
+
implementation?: string;
|
|
50
50
|
manifest?: ManifestOptions | boolean;
|
|
51
51
|
dev?: boolean | PluginDevOptions;
|
|
52
52
|
dts?: boolean | PluginDtsOptions;
|
|
@@ -62,7 +62,7 @@ export interface NormalizedModuleFederationOptions {
|
|
|
62
62
|
shareScope: string;
|
|
63
63
|
shared: NormalizedShared;
|
|
64
64
|
runtimePlugins: string[];
|
|
65
|
-
implementation:
|
|
65
|
+
implementation: string;
|
|
66
66
|
manifest: ManifestOptions | boolean;
|
|
67
67
|
dev?: boolean | PluginDevOptions;
|
|
68
68
|
dts?: boolean | PluginDtsOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Vite plugin for Module Federation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,6 +9,22 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"lib/**/*"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepare": "husky install",
|
|
14
|
+
"fmt": "prettier --write src",
|
|
15
|
+
"fmt.check": "prettier --check src",
|
|
16
|
+
"format": "pretty-quick",
|
|
17
|
+
"dev": "microbundle watch --no-sourcemap --compress=false",
|
|
18
|
+
"build": "rimraf lib && microbundle --no-sourcemap --compress=false",
|
|
19
|
+
"dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
|
|
20
|
+
"preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
|
|
21
|
+
"dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
|
|
22
|
+
"dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
|
|
23
|
+
"preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
|
|
24
|
+
"multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"e2e": "playwright test"
|
|
27
|
+
},
|
|
12
28
|
"repository": {
|
|
13
29
|
"type": "git",
|
|
14
30
|
"url": "git+https://github.com/module-federation/vite.git"
|
|
@@ -28,14 +44,15 @@
|
|
|
28
44
|
"url": "https://github.com/module-federation/vite/issues"
|
|
29
45
|
},
|
|
30
46
|
"homepage": "https://github.com/module-federation/vite#readme",
|
|
47
|
+
"packageManager": "pnpm@9.1.3",
|
|
31
48
|
"dependencies": {
|
|
32
|
-
"@module-federation/runtime": "^0.
|
|
49
|
+
"@module-federation/runtime": "^0.7.1",
|
|
33
50
|
"@rollup/pluginutils": "^5.1.0",
|
|
34
51
|
"defu": "^6.1.4",
|
|
35
52
|
"estree-walker": "^2",
|
|
36
53
|
"magic-string": "^0.30.11",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
54
|
+
"pathe": "^1.1.2",
|
|
55
|
+
"vitest": "^2.1.1"
|
|
39
56
|
},
|
|
40
57
|
"devDependencies": {
|
|
41
58
|
"@playwright/test": "^1.47.2",
|
|
@@ -48,20 +65,5 @@
|
|
|
48
65
|
"rimraf": "^6.0.1",
|
|
49
66
|
"vite": "^5.4.3",
|
|
50
67
|
"wait-on": "^8.0.1"
|
|
51
|
-
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"fmt": "prettier --write src",
|
|
54
|
-
"fmt.check": "prettier --check src",
|
|
55
|
-
"format": "pretty-quick",
|
|
56
|
-
"dev": "microbundle watch --no-sourcemap --compress=false",
|
|
57
|
-
"build": "rimraf lib && microbundle --no-sourcemap --compress=false",
|
|
58
|
-
"dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
|
|
59
|
-
"preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
|
|
60
|
-
"dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
|
|
61
|
-
"dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
|
|
62
|
-
"preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
|
|
63
|
-
"multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
|
|
64
|
-
"test": "vitest",
|
|
65
|
-
"e2e": "playwright test"
|
|
66
68
|
}
|
|
67
|
-
}
|
|
69
|
+
}
|