@module-federation/vite 1.1.6 → 1.1.8

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 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
@@ -30,6 +30,11 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
30
30
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
31
31
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
32
32
 
33
+ function getFirstHtmlEntryFile(entryFiles) {
34
+ return entryFiles.find(function (file) {
35
+ return file.endsWith('.html');
36
+ });
37
+ }
33
38
  var addEntry = function addEntry(_ref) {
34
39
  var entryName = _ref.entryName,
35
40
  entryPath = _ref.entryPath,
@@ -42,6 +47,12 @@ var addEntry = function addEntry(_ref) {
42
47
  var _command;
43
48
  var emitFileId;
44
49
  var viteConfig;
50
+ function injectHtml() {
51
+ return inject === 'html' && htmlFilePath;
52
+ }
53
+ function injectEntry() {
54
+ return inject === 'entry' || !htmlFilePath;
55
+ }
45
56
  return [{
46
57
  name: 'add-entry',
47
58
  apply: 'serve',
@@ -71,6 +82,7 @@ var addEntry = function addEntry(_ref) {
71
82
  });
72
83
  },
73
84
  transformIndexHtml: function transformIndexHtml(c) {
85
+ if (!injectHtml()) return;
74
86
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
75
87
  }
76
88
  }, {
@@ -83,13 +95,13 @@ var addEntry = function addEntry(_ref) {
83
95
  htmlFilePath = path__namespace.resolve(config.root, 'index.html');
84
96
  } else if (typeof inputOptions === 'string') {
85
97
  entryFiles = [inputOptions];
86
- htmlFilePath = path__namespace.resolve(config.root, inputOptions);
87
98
  } else if (Array.isArray(inputOptions)) {
88
99
  entryFiles = inputOptions;
89
- htmlFilePath = path__namespace.resolve(config.root, inputOptions[0]);
90
100
  } else if (typeof inputOptions === 'object') {
91
101
  entryFiles = Object.values(inputOptions);
92
- htmlFilePath = path__namespace.resolve(config.root, Object.values(inputOptions)[0]);
102
+ }
103
+ if (entryFiles && entryFiles.length > 0) {
104
+ htmlFilePath = getFirstHtmlEntryFile(entryFiles);
93
105
  }
94
106
  },
95
107
  buildStart: function buildStart() {
@@ -115,7 +127,7 @@ var addEntry = function addEntry(_ref) {
115
127
  }
116
128
  },
117
129
  generateBundle: function generateBundle(options, bundle) {
118
- if (inject !== 'html') return;
130
+ if (!injectHtml()) return;
119
131
  var file = this.getFileName(emitFileId);
120
132
  var scriptContent = "\n <script type=\"module\" src=\"" + (viteConfig.base + file) + "\"></script>\n ";
121
133
  for (var _fileName in bundle) {
@@ -129,7 +141,7 @@ var addEntry = function addEntry(_ref) {
129
141
  }
130
142
  },
131
143
  transform: function transform(code, id) {
132
- if (inject === 'entry' && entryFiles.some(function (file) {
144
+ if (injectEntry() && entryFiles.some(function (file) {
133
145
  return id.endsWith(file);
134
146
  })) {
135
147
  var injection = "\n import " + JSON.stringify(entryPath) + ";\n ";
@@ -401,7 +413,7 @@ function normalizeModuleFederationOptions(options) {
401
413
  shareScope: options.shareScope || 'default',
402
414
  shared: normalizeShared(options.shared),
403
415
  runtimePlugins: options.runtimePlugins || [],
404
- implementation: options.implementation,
416
+ implementation: options.implementation || require.resolve('@module-federation/runtime'),
405
417
  manifest: normalizeManifest(options.manifest),
406
418
  dev: options.dev,
407
419
  dts: options.dts,
@@ -629,10 +641,16 @@ function generateLocalSharedImportMap() {
629
641
  return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
630
642
  }).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
631
643
  var shareItem = getNormalizeShareItem(key);
644
+ if (!shareItem) return null;
632
645
  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 ";
646
+ }).filter(function (x) {
647
+ return x !== null;
633
648
  }).join(',') + "\n }\n const usedRemotes = [" + Object.keys(getUsedRemotesMap()).map(function (key) {
634
649
  var remote = options.remotes[key];
650
+ if (!remote) return null;
635
651
  return "\n {\n entryGlobalName: " + JSON.stringify(remote.entryGlobalName) + ",\n name: " + JSON.stringify(remote.name) + ",\n type: " + JSON.stringify(remote.type) + ",\n entry: " + JSON.stringify(remote.entry) + ",\n }\n ";
652
+ }).filter(function (x) {
653
+ return x !== null;
636
654
  }).join(',') + "\n ]\n export {\n usedShared,\n usedRemotes\n }\n ";
637
655
  }
638
656
  var REMOTE_ENTRY_ID = 'virtual:mf-REMOTE_ENTRY_ID';
@@ -642,9 +660,9 @@ function generateRemoteEntry(options) {
642
660
  });
643
661
  return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
644
662
  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: " + JSON.stringify(options.name) + ",\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
663
+ }).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
664
  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 ";
665
+ }).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
666
  }
649
667
  /**
650
668
  * Inject entry file, automatically init when used as host,
@@ -1025,9 +1043,17 @@ function pluginModuleParseEnd (excludeFn) {
1025
1043
 
1026
1044
  var filter = pluginutils.createFilter();
1027
1045
  function pluginProxyRemoteEntry () {
1046
+ var viteConfig, _command;
1028
1047
  return {
1029
1048
  name: 'proxyRemoteEntry',
1030
1049
  enforce: 'post',
1050
+ configResolved: function configResolved(config) {
1051
+ viteConfig = config;
1052
+ },
1053
+ config: function config(_config, _ref) {
1054
+ var command = _ref.command;
1055
+ _command = command;
1056
+ },
1031
1057
  resolveId: function resolveId(id) {
1032
1058
  if (id === REMOTE_ENTRY_ID) {
1033
1059
  return REMOTE_ENTRY_ID;
@@ -1035,6 +1061,9 @@ function pluginProxyRemoteEntry () {
1035
1061
  if (id === VIRTUAL_EXPOSES) {
1036
1062
  return VIRTUAL_EXPOSES;
1037
1063
  }
1064
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1065
+ return id;
1066
+ }
1038
1067
  },
1039
1068
  load: function load(id) {
1040
1069
  if (id === REMOTE_ENTRY_ID) {
@@ -1045,6 +1074,9 @@ function pluginProxyRemoteEntry () {
1045
1074
  if (id === VIRTUAL_EXPOSES) {
1046
1075
  return generateExposes();
1047
1076
  }
1077
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1078
+ return id;
1079
+ }
1048
1080
  },
1049
1081
  transform: function transform(code, id) {
1050
1082
  try {
@@ -1057,6 +1089,14 @@ function pluginProxyRemoteEntry () {
1057
1089
  if (id === VIRTUAL_EXPOSES) {
1058
1090
  return Promise.resolve(generateExposes());
1059
1091
  }
1092
+ if (id.includes(getHostAutoInitPath())) {
1093
+ var options = getNormalizeModuleFederationOptions();
1094
+ if (_command === 'serve') {
1095
+ var _viteConfig$server;
1096
+ 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 ");
1097
+ }
1098
+ return Promise.resolve(code);
1099
+ }
1060
1100
  return Promise.resolve();
1061
1101
  } catch (e) {
1062
1102
  return Promise.reject(e);
@@ -1293,7 +1333,7 @@ function federation(mfUserOptions) {
1293
1333
  // TODO: singleton
1294
1334
  _config.resolve.alias.push({
1295
1335
  find: '@module-federation/runtime',
1296
- replacement: require.resolve('@module-federation/runtime')
1336
+ replacement: options.implementation
1297
1337
  });
1298
1338
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1299
1339
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
package/lib/index.esm.js CHANGED
@@ -7,6 +7,11 @@ import { walk } from 'estree-walker';
7
7
  import MagicString from 'magic-string';
8
8
  import { defu } from 'defu';
9
9
 
10
+ function getFirstHtmlEntryFile(entryFiles) {
11
+ return entryFiles.find(function (file) {
12
+ return file.endsWith('.html');
13
+ });
14
+ }
10
15
  var addEntry = function addEntry(_ref) {
11
16
  var entryName = _ref.entryName,
12
17
  entryPath = _ref.entryPath,
@@ -19,6 +24,12 @@ var addEntry = function addEntry(_ref) {
19
24
  var _command;
20
25
  var emitFileId;
21
26
  var viteConfig;
27
+ function injectHtml() {
28
+ return inject === 'html' && htmlFilePath;
29
+ }
30
+ function injectEntry() {
31
+ return inject === 'entry' || !htmlFilePath;
32
+ }
22
33
  return [{
23
34
  name: 'add-entry',
24
35
  apply: 'serve',
@@ -48,6 +59,7 @@ var addEntry = function addEntry(_ref) {
48
59
  });
49
60
  },
50
61
  transformIndexHtml: function transformIndexHtml(c) {
62
+ if (!injectHtml()) return;
51
63
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
52
64
  }
53
65
  }, {
@@ -60,13 +72,13 @@ var addEntry = function addEntry(_ref) {
60
72
  htmlFilePath = path.resolve(config.root, 'index.html');
61
73
  } else if (typeof inputOptions === 'string') {
62
74
  entryFiles = [inputOptions];
63
- htmlFilePath = path.resolve(config.root, inputOptions);
64
75
  } else if (Array.isArray(inputOptions)) {
65
76
  entryFiles = inputOptions;
66
- htmlFilePath = path.resolve(config.root, inputOptions[0]);
67
77
  } else if (typeof inputOptions === 'object') {
68
78
  entryFiles = Object.values(inputOptions);
69
- htmlFilePath = path.resolve(config.root, Object.values(inputOptions)[0]);
79
+ }
80
+ if (entryFiles && entryFiles.length > 0) {
81
+ htmlFilePath = getFirstHtmlEntryFile(entryFiles);
70
82
  }
71
83
  },
72
84
  buildStart: function buildStart() {
@@ -92,7 +104,7 @@ var addEntry = function addEntry(_ref) {
92
104
  }
93
105
  },
94
106
  generateBundle: function generateBundle(options, bundle) {
95
- if (inject !== 'html') return;
107
+ if (!injectHtml()) return;
96
108
  var file = this.getFileName(emitFileId);
97
109
  var scriptContent = "\n <script type=\"module\" src=\"" + (viteConfig.base + file) + "\"></script>\n ";
98
110
  for (var _fileName in bundle) {
@@ -106,7 +118,7 @@ var addEntry = function addEntry(_ref) {
106
118
  }
107
119
  },
108
120
  transform: function transform(code, id) {
109
- if (inject === 'entry' && entryFiles.some(function (file) {
121
+ if (injectEntry() && entryFiles.some(function (file) {
110
122
  return id.endsWith(file);
111
123
  })) {
112
124
  var injection = "\n import " + JSON.stringify(entryPath) + ";\n ";
@@ -378,7 +390,7 @@ function normalizeModuleFederationOptions(options) {
378
390
  shareScope: options.shareScope || 'default',
379
391
  shared: normalizeShared(options.shared),
380
392
  runtimePlugins: options.runtimePlugins || [],
381
- implementation: options.implementation,
393
+ implementation: options.implementation || require.resolve('@module-federation/runtime'),
382
394
  manifest: normalizeManifest(options.manifest),
383
395
  dev: options.dev,
384
396
  dts: options.dts,
@@ -606,10 +618,16 @@ function generateLocalSharedImportMap() {
606
618
  return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
607
619
  }).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
608
620
  var shareItem = getNormalizeShareItem(key);
621
+ if (!shareItem) return null;
609
622
  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 ";
623
+ }).filter(function (x) {
624
+ return x !== null;
610
625
  }).join(',') + "\n }\n const usedRemotes = [" + Object.keys(getUsedRemotesMap()).map(function (key) {
611
626
  var remote = options.remotes[key];
627
+ if (!remote) return null;
612
628
  return "\n {\n entryGlobalName: " + JSON.stringify(remote.entryGlobalName) + ",\n name: " + JSON.stringify(remote.name) + ",\n type: " + JSON.stringify(remote.type) + ",\n entry: " + JSON.stringify(remote.entry) + ",\n }\n ";
629
+ }).filter(function (x) {
630
+ return x !== null;
613
631
  }).join(',') + "\n ]\n export {\n usedShared,\n usedRemotes\n }\n ";
614
632
  }
615
633
  var REMOTE_ENTRY_ID = 'virtual:mf-REMOTE_ENTRY_ID';
@@ -619,9 +637,9 @@ function generateRemoteEntry(options) {
619
637
  });
620
638
  return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
621
639
  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: " + JSON.stringify(options.name) + ",\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
640
+ }).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
641
  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 ";
642
+ }).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
643
  }
626
644
  /**
627
645
  * Inject entry file, automatically init when used as host,
@@ -1002,9 +1020,17 @@ function pluginModuleParseEnd (excludeFn) {
1002
1020
 
1003
1021
  var filter = createFilter();
1004
1022
  function pluginProxyRemoteEntry () {
1023
+ var viteConfig, _command;
1005
1024
  return {
1006
1025
  name: 'proxyRemoteEntry',
1007
1026
  enforce: 'post',
1027
+ configResolved: function configResolved(config) {
1028
+ viteConfig = config;
1029
+ },
1030
+ config: function config(_config, _ref) {
1031
+ var command = _ref.command;
1032
+ _command = command;
1033
+ },
1008
1034
  resolveId: function resolveId(id) {
1009
1035
  if (id === REMOTE_ENTRY_ID) {
1010
1036
  return REMOTE_ENTRY_ID;
@@ -1012,6 +1038,9 @@ function pluginProxyRemoteEntry () {
1012
1038
  if (id === VIRTUAL_EXPOSES) {
1013
1039
  return VIRTUAL_EXPOSES;
1014
1040
  }
1041
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1042
+ return id;
1043
+ }
1015
1044
  },
1016
1045
  load: function load(id) {
1017
1046
  if (id === REMOTE_ENTRY_ID) {
@@ -1022,6 +1051,9 @@ function pluginProxyRemoteEntry () {
1022
1051
  if (id === VIRTUAL_EXPOSES) {
1023
1052
  return generateExposes();
1024
1053
  }
1054
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1055
+ return id;
1056
+ }
1025
1057
  },
1026
1058
  transform: function transform(code, id) {
1027
1059
  try {
@@ -1034,6 +1066,14 @@ function pluginProxyRemoteEntry () {
1034
1066
  if (id === VIRTUAL_EXPOSES) {
1035
1067
  return Promise.resolve(generateExposes());
1036
1068
  }
1069
+ if (id.includes(getHostAutoInitPath())) {
1070
+ var options = getNormalizeModuleFederationOptions();
1071
+ if (_command === 'serve') {
1072
+ var _viteConfig$server;
1073
+ 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 ");
1074
+ }
1075
+ return Promise.resolve(code);
1076
+ }
1037
1077
  return Promise.resolve();
1038
1078
  } catch (e) {
1039
1079
  return Promise.reject(e);
@@ -1270,7 +1310,7 @@ function federation(mfUserOptions) {
1270
1310
  // TODO: singleton
1271
1311
  _config.resolve.alias.push({
1272
1312
  find: '@module-federation/runtime',
1273
- replacement: require.resolve('@module-federation/runtime')
1313
+ replacement: options.implementation
1274
1314
  });
1275
1315
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1276
1316
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
@@ -7,6 +7,9 @@ import { walk } from 'estree-walker';
7
7
  import MagicString from 'magic-string';
8
8
  import { defu } from 'defu';
9
9
 
10
+ function getFirstHtmlEntryFile(entryFiles) {
11
+ return entryFiles.find(file => file.endsWith('.html'));
12
+ }
10
13
  const addEntry = ({
11
14
  entryName,
12
15
  entryPath,
@@ -19,6 +22,12 @@ const addEntry = ({
19
22
  let _command;
20
23
  let emitFileId;
21
24
  let viteConfig;
25
+ function injectHtml() {
26
+ return _inject === 'html' && htmlFilePath;
27
+ }
28
+ function injectEntry() {
29
+ return _inject === 'entry' || !htmlFilePath;
30
+ }
22
31
  return [{
23
32
  name: 'add-entry',
24
33
  apply: 'serve',
@@ -51,6 +60,7 @@ const addEntry = ({
51
60
  });
52
61
  },
53
62
  transformIndexHtml(c) {
63
+ if (!injectHtml()) return;
54
64
  return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/'))}></script>`);
55
65
  }
56
66
  }, {
@@ -63,13 +73,13 @@ const addEntry = ({
63
73
  htmlFilePath = path.resolve(config.root, 'index.html');
64
74
  } else if (typeof inputOptions === 'string') {
65
75
  entryFiles = [inputOptions];
66
- htmlFilePath = path.resolve(config.root, inputOptions);
67
76
  } else if (Array.isArray(inputOptions)) {
68
77
  entryFiles = inputOptions;
69
- htmlFilePath = path.resolve(config.root, inputOptions[0]);
70
78
  } else if (typeof inputOptions === 'object') {
71
79
  entryFiles = Object.values(inputOptions);
72
- htmlFilePath = path.resolve(config.root, Object.values(inputOptions)[0]);
80
+ }
81
+ if (entryFiles && entryFiles.length > 0) {
82
+ htmlFilePath = getFirstHtmlEntryFile(entryFiles);
73
83
  }
74
84
  },
75
85
  buildStart() {
@@ -95,7 +105,7 @@ const addEntry = ({
95
105
  }
96
106
  },
97
107
  generateBundle(options, bundle) {
98
- if (_inject !== 'html') return;
108
+ if (!injectHtml()) return;
99
109
  const file = this.getFileName(emitFileId);
100
110
  const scriptContent = `
101
111
  <script type="module" src="${viteConfig.base + file}"></script>
@@ -111,7 +121,7 @@ const addEntry = ({
111
121
  }
112
122
  },
113
123
  transform(code, id) {
114
- if (_inject === 'entry' && entryFiles.some(file => id.endsWith(file))) {
124
+ if (injectEntry() && entryFiles.some(file => id.endsWith(file))) {
115
125
  const injection = `
116
126
  import ${JSON.stringify(entryPath)};
117
127
  `;
@@ -352,7 +362,7 @@ function normalizeModuleFederationOptions(options) {
352
362
  shareScope: options.shareScope || 'default',
353
363
  shared: normalizeShared(options.shared),
354
364
  runtimePlugins: options.runtimePlugins || [],
355
- implementation: options.implementation,
365
+ implementation: options.implementation || require.resolve('@module-federation/runtime'),
356
366
  manifest: normalizeManifest(options.manifest),
357
367
  dev: options.dev,
358
368
  dts: options.dts,
@@ -623,6 +633,7 @@ function generateLocalSharedImportMap() {
623
633
  const usedShared = {
624
634
  ${Array.from(getUsedShares()).map(key => {
625
635
  const shareItem = getNormalizeShareItem(key);
636
+ if (!shareItem) return null;
626
637
  return `
627
638
  ${JSON.stringify(key)}: {
628
639
  name: ${JSON.stringify(key)},
@@ -650,10 +661,11 @@ function generateLocalSharedImportMap() {
650
661
  }
651
662
  }
652
663
  `;
653
- }).join(',')}
664
+ }).filter(x => x !== null).join(',')}
654
665
  }
655
666
  const usedRemotes = [${Object.keys(getUsedRemotesMap()).map(key => {
656
667
  const remote = options.remotes[key];
668
+ if (!remote) return null;
657
669
  return `
658
670
  {
659
671
  entryGlobalName: ${JSON.stringify(remote.entryGlobalName)},
@@ -662,7 +674,7 @@ function generateLocalSharedImportMap() {
662
674
  entry: ${JSON.stringify(remote.entry)},
663
675
  }
664
676
  `;
665
- }).join(',')}
677
+ }).filter(x => x !== null).join(',')}
666
678
  ]
667
679
  export {
668
680
  usedShared,
@@ -681,17 +693,30 @@ function generateRemoteEntry(options) {
681
693
  import {
682
694
  initResolve
683
695
  } from "${virtualRuntimeInitStatus.getImportId()}"
684
- async function init(shared = {}) {
696
+ const initTokens = {}
697
+ const shareScopeName = ${JSON.stringify(options.shareScope)}
698
+ const mfName = ${JSON.stringify(options.name)}
699
+ async function init(shared = {}, initScope = []) {
685
700
  const initRes = runtimeInit({
686
- name: ${JSON.stringify(options.name)},
701
+ name: mfName,
687
702
  remotes: usedRemotes,
688
703
  shared: usedShared,
689
704
  plugins: [${pluginImportNames.map(item => `${item[0]}()`).join(', ')}],
690
705
  ${options.shareStrategy ? `shareStrategy: '${options.shareStrategy}'` : ''}
691
706
  });
707
+ // handling circular init calls
708
+ var initToken = initTokens[shareScopeName];
709
+ if (!initToken)
710
+ initToken = initTokens[shareScopeName] = { from: mfName };
711
+ if (initScope.indexOf(initToken) >= 0) return;
712
+ initScope.push(initToken);
692
713
  initRes.initShareScopeMap('${options.shareScope}', shared);
693
714
  try {
694
- await Promise.all(await initRes.initializeSharing('${options.shareScope}', {strategy: '${options.shareStrategy}'}));
715
+ await Promise.all(await initRes.initializeSharing('${options.shareScope}', {
716
+ strategy: '${options.shareStrategy}',
717
+ from: "build",
718
+ initScope
719
+ }));
695
720
  } catch (e) {
696
721
  console.error(e)
697
722
  }
@@ -1066,9 +1091,18 @@ function pluginModuleParseEnd (excludeFn) {
1066
1091
 
1067
1092
  const filter = createFilter();
1068
1093
  function pluginProxyRemoteEntry () {
1094
+ let viteConfig, _command;
1069
1095
  return {
1070
1096
  name: 'proxyRemoteEntry',
1071
1097
  enforce: 'post',
1098
+ configResolved(config) {
1099
+ viteConfig = config;
1100
+ },
1101
+ config(config, {
1102
+ command
1103
+ }) {
1104
+ _command = command;
1105
+ },
1072
1106
  resolveId(id) {
1073
1107
  if (id === REMOTE_ENTRY_ID) {
1074
1108
  return REMOTE_ENTRY_ID;
@@ -1076,6 +1110,9 @@ function pluginProxyRemoteEntry () {
1076
1110
  if (id === VIRTUAL_EXPOSES) {
1077
1111
  return VIRTUAL_EXPOSES;
1078
1112
  }
1113
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1114
+ return id;
1115
+ }
1079
1116
  },
1080
1117
  load(id) {
1081
1118
  if (id === REMOTE_ENTRY_ID) {
@@ -1084,6 +1121,9 @@ function pluginProxyRemoteEntry () {
1084
1121
  if (id === VIRTUAL_EXPOSES) {
1085
1122
  return generateExposes();
1086
1123
  }
1124
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1125
+ return id;
1126
+ }
1087
1127
  },
1088
1128
  async transform(code, id) {
1089
1129
  if (!filter(id)) return;
@@ -1093,6 +1133,17 @@ function pluginProxyRemoteEntry () {
1093
1133
  if (id === VIRTUAL_EXPOSES) {
1094
1134
  return generateExposes();
1095
1135
  }
1136
+ if (id.includes(getHostAutoInitPath())) {
1137
+ const options = getNormalizeModuleFederationOptions();
1138
+ if (_command === 'serve') {
1139
+ var _viteConfig$server;
1140
+ return `
1141
+ const {init} = await import("//localhost:${(_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port}${viteConfig.base + options.filename}")
1142
+ init()
1143
+ `;
1144
+ }
1145
+ return code;
1146
+ }
1096
1147
  }
1097
1148
  };
1098
1149
  }
@@ -1322,7 +1373,7 @@ function federation(mfUserOptions) {
1322
1373
  // TODO: singleton
1323
1374
  config.resolve.alias.push({
1324
1375
  find: '@module-federation/runtime',
1325
- replacement: require.resolve('@module-federation/runtime')
1376
+ replacement: options.implementation
1326
1377
  });
1327
1378
  (_config$optimizeDeps = config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1328
1379
  (_config$optimizeDeps2 = config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
package/lib/index.umd.js CHANGED
@@ -28,6 +28,11 @@
28
28
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
29
29
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
30
30
 
31
+ function getFirstHtmlEntryFile(entryFiles) {
32
+ return entryFiles.find(function (file) {
33
+ return file.endsWith('.html');
34
+ });
35
+ }
31
36
  var addEntry = function addEntry(_ref) {
32
37
  var entryName = _ref.entryName,
33
38
  entryPath = _ref.entryPath,
@@ -40,6 +45,12 @@
40
45
  var _command;
41
46
  var emitFileId;
42
47
  var viteConfig;
48
+ function injectHtml() {
49
+ return inject === 'html' && htmlFilePath;
50
+ }
51
+ function injectEntry() {
52
+ return inject === 'entry' || !htmlFilePath;
53
+ }
43
54
  return [{
44
55
  name: 'add-entry',
45
56
  apply: 'serve',
@@ -69,6 +80,7 @@
69
80
  });
70
81
  },
71
82
  transformIndexHtml: function transformIndexHtml(c) {
83
+ if (!injectHtml()) return;
72
84
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
73
85
  }
74
86
  }, {
@@ -81,13 +93,13 @@
81
93
  htmlFilePath = path__namespace.resolve(config.root, 'index.html');
82
94
  } else if (typeof inputOptions === 'string') {
83
95
  entryFiles = [inputOptions];
84
- htmlFilePath = path__namespace.resolve(config.root, inputOptions);
85
96
  } else if (Array.isArray(inputOptions)) {
86
97
  entryFiles = inputOptions;
87
- htmlFilePath = path__namespace.resolve(config.root, inputOptions[0]);
88
98
  } else if (typeof inputOptions === 'object') {
89
99
  entryFiles = Object.values(inputOptions);
90
- htmlFilePath = path__namespace.resolve(config.root, Object.values(inputOptions)[0]);
100
+ }
101
+ if (entryFiles && entryFiles.length > 0) {
102
+ htmlFilePath = getFirstHtmlEntryFile(entryFiles);
91
103
  }
92
104
  },
93
105
  buildStart: function buildStart() {
@@ -113,7 +125,7 @@
113
125
  }
114
126
  },
115
127
  generateBundle: function generateBundle(options, bundle) {
116
- if (inject !== 'html') return;
128
+ if (!injectHtml()) return;
117
129
  var file = this.getFileName(emitFileId);
118
130
  var scriptContent = "\n <script type=\"module\" src=\"" + (viteConfig.base + file) + "\"></script>\n ";
119
131
  for (var _fileName in bundle) {
@@ -127,7 +139,7 @@
127
139
  }
128
140
  },
129
141
  transform: function transform(code, id) {
130
- if (inject === 'entry' && entryFiles.some(function (file) {
142
+ if (injectEntry() && entryFiles.some(function (file) {
131
143
  return id.endsWith(file);
132
144
  })) {
133
145
  var injection = "\n import " + JSON.stringify(entryPath) + ";\n ";
@@ -399,7 +411,7 @@
399
411
  shareScope: options.shareScope || 'default',
400
412
  shared: normalizeShared(options.shared),
401
413
  runtimePlugins: options.runtimePlugins || [],
402
- implementation: options.implementation,
414
+ implementation: options.implementation || require.resolve('@module-federation/runtime'),
403
415
  manifest: normalizeManifest(options.manifest),
404
416
  dev: options.dev,
405
417
  dts: options.dts,
@@ -627,10 +639,16 @@
627
639
  return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
628
640
  }).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
629
641
  var shareItem = getNormalizeShareItem(key);
642
+ if (!shareItem) return null;
630
643
  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 ";
644
+ }).filter(function (x) {
645
+ return x !== null;
631
646
  }).join(',') + "\n }\n const usedRemotes = [" + Object.keys(getUsedRemotesMap()).map(function (key) {
632
647
  var remote = options.remotes[key];
648
+ if (!remote) return null;
633
649
  return "\n {\n entryGlobalName: " + JSON.stringify(remote.entryGlobalName) + ",\n name: " + JSON.stringify(remote.name) + ",\n type: " + JSON.stringify(remote.type) + ",\n entry: " + JSON.stringify(remote.entry) + ",\n }\n ";
650
+ }).filter(function (x) {
651
+ return x !== null;
634
652
  }).join(',') + "\n ]\n export {\n usedShared,\n usedRemotes\n }\n ";
635
653
  }
636
654
  var REMOTE_ENTRY_ID = 'virtual:mf-REMOTE_ENTRY_ID';
@@ -640,9 +658,9 @@
640
658
  });
641
659
  return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
642
660
  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: " + JSON.stringify(options.name) + ",\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
661
+ }).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
662
  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 ";
663
+ }).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
664
  }
647
665
  /**
648
666
  * Inject entry file, automatically init when used as host,
@@ -1023,9 +1041,17 @@
1023
1041
 
1024
1042
  var filter = pluginutils.createFilter();
1025
1043
  function pluginProxyRemoteEntry () {
1044
+ var viteConfig, _command;
1026
1045
  return {
1027
1046
  name: 'proxyRemoteEntry',
1028
1047
  enforce: 'post',
1048
+ configResolved: function configResolved(config) {
1049
+ viteConfig = config;
1050
+ },
1051
+ config: function config(_config, _ref) {
1052
+ var command = _ref.command;
1053
+ _command = command;
1054
+ },
1029
1055
  resolveId: function resolveId(id) {
1030
1056
  if (id === REMOTE_ENTRY_ID) {
1031
1057
  return REMOTE_ENTRY_ID;
@@ -1033,6 +1059,9 @@
1033
1059
  if (id === VIRTUAL_EXPOSES) {
1034
1060
  return VIRTUAL_EXPOSES;
1035
1061
  }
1062
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1063
+ return id;
1064
+ }
1036
1065
  },
1037
1066
  load: function load(id) {
1038
1067
  if (id === REMOTE_ENTRY_ID) {
@@ -1043,6 +1072,9 @@
1043
1072
  if (id === VIRTUAL_EXPOSES) {
1044
1073
  return generateExposes();
1045
1074
  }
1075
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1076
+ return id;
1077
+ }
1046
1078
  },
1047
1079
  transform: function transform(code, id) {
1048
1080
  try {
@@ -1055,6 +1087,14 @@
1055
1087
  if (id === VIRTUAL_EXPOSES) {
1056
1088
  return Promise.resolve(generateExposes());
1057
1089
  }
1090
+ if (id.includes(getHostAutoInitPath())) {
1091
+ var options = getNormalizeModuleFederationOptions();
1092
+ if (_command === 'serve') {
1093
+ var _viteConfig$server;
1094
+ 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 ");
1095
+ }
1096
+ return Promise.resolve(code);
1097
+ }
1058
1098
  return Promise.resolve();
1059
1099
  } catch (e) {
1060
1100
  return Promise.reject(e);
@@ -1291,7 +1331,7 @@
1291
1331
  // TODO: singleton
1292
1332
  _config.resolve.alias.push({
1293
1333
  find: '@module-federation/runtime',
1294
- replacement: require.resolve('@module-federation/runtime')
1334
+ replacement: options.implementation
1295
1335
  });
1296
1336
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1297
1337
  (_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?: any;
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: any;
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.6",
3
+ "version": "1.1.8",
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,14 @@
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.7.1",
49
+ "@module-federation/runtime": "^0.8.0",
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
- "pathe": "^1.1.2",
38
- "vitest": "^2.1.1"
54
+ "pathe": "^1.1.2"
39
55
  },
40
56
  "devDependencies": {
41
57
  "@playwright/test": "^1.47.2",
@@ -47,21 +63,7 @@
47
63
  "pretty-quick": "^4.0.0",
48
64
  "rimraf": "^6.0.1",
49
65
  "vite": "^5.4.3",
66
+ "vitest": "^2.1.1",
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
+ }