@module-federation/vite 1.0.0-alpha-def937d → 1.0.0-alpha-6cae9ab

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
@@ -56,6 +56,11 @@ export default defineConfig({
56
56
  // If you set build.target: "chrome89", you can remove this plugin
57
57
  // topLevelAwait(),
58
58
  ],
59
+ server: {
60
+ port: 5173,
61
+ // dev mode please set origin
62
+ origin: "http://localhost:5173"
63
+ },
59
64
  build: {
60
65
  target: 'chrome89',
61
66
  },
@@ -72,6 +77,7 @@ export default defineConfig({
72
77
  - feat: download remote d.ts
73
78
  - feat: generate d.ts
74
79
  - feat: support @vitejs/plugin-legacy
80
+ - feat: Another plugin, when only some remote modules are started, automatically completes HMR[(#54)](https://github.com/module-federation/vite/issues/54)
75
81
 
76
82
  ### So far so good 🎉
77
83
 
package/lib/index.cjs CHANGED
@@ -149,10 +149,18 @@ function normalizeRemoteItem(key, remote) {
149
149
  entryGlobalName: key
150
150
  }, remote);
151
151
  }
152
+ function removePathFromNpmPackage(packageString) {
153
+ // 匹配npm包名的正则表达式,忽略路径部分
154
+ var regex = /^(?:@[^/]+\/)?[^/]+/;
155
+ // 使用正则表达式匹配并提取包名
156
+ var match = packageString.match(regex);
157
+ // 返回匹配到的包名,如果没有匹配到则返回原字符串
158
+ return match ? match[0] : packageString;
159
+ }
152
160
  function normalizeShareItem(key, shareItem) {
153
161
  var version;
154
162
  try {
155
- version = require(path__namespace.join(key, 'package.json')).version;
163
+ version = require(path__namespace.join(removePathFromNpmPackage(key), 'package.json')).version;
156
164
  } catch (e) {
157
165
  console.log(e);
158
166
  }
@@ -268,7 +276,7 @@ function getLoadShareModulePath(pkg) {
268
276
  return path.resolve(emptyNpmDir, filename);
269
277
  }
270
278
  function writeLoadShareModule(pkg, shareItem, command) {
271
- fs.writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = 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 ");
279
+ fs.writeFileSync(getLoadShareModulePath(pkg), "\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 res = 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 ");
272
280
  }
273
281
  function npmPackageNameToFileName(packageName) {
274
282
  // 1. 去掉包名前的 "@"
@@ -280,7 +288,7 @@ function npmPackageNameToFileName(packageName) {
280
288
  }
281
289
 
282
290
  var emptyPath = require.resolve('an-empty-js-file');
283
- var REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
291
+ var REMOTE_ENTRY_ID = 'REMOTE_ENTRY_ID';
284
292
  function generateRemoteEntry(options) {
285
293
  var pluginImportNames = options.runtimePlugins.map(function (p, i) {
286
294
  return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p + "\";"];
@@ -291,7 +299,7 @@ function generateRemoteEntry(options) {
291
299
  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 ";
292
300
  }).join(',') + "\n }\n import localSharedImportMap from \"" + getLocalSharedImportMapId() + "\"\n async function init(shared = {}) {\n const localShared = {\n " + Object.keys(options.shared).map(function (key) {
293
301
  var shareItem = options.shared[key];
294
- return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \n const res = await pkgDynamicImport()\n return function () {\n return res\n }\n },\n shareConfig: {\n singleton: " + shareItem.shareConfig.singleton + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }\n }\n ";
302
+ return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \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 ";
295
303
  }).join(',') + "\n }\n const initRes = runtimeInit({\n name: " + JSON.stringify(options.name) + ",\n remotes: [" + Object.keys(options.remotes).map(function (key) {
296
304
  var remote = options.remotes[key];
297
305
  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 ";
@@ -299,7 +307,7 @@ function generateRemoteEntry(options) {
299
307
  return item[0] + "()";
300
308
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
301
309
  }
302
- var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
310
+ var WRAP_REMOTE_ENTRY_QUERY_STR = '__mf__wrapRemoteEntry__';
303
311
  var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
304
312
  function generateWrapRemoteEntry() {
305
313
  return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
@@ -308,7 +316,7 @@ function generateWrapRemoteEntry() {
308
316
  * Inject entry file, automatically init when used as host,
309
317
  * and will not inject remoteEntry
310
318
  */
311
- var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
319
+ var HOST_AUTO_INIT_QUERY_STR = '__mf__isHostInit';
312
320
  var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
313
321
  function generateWrapHostInit() {
314
322
  return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
package/lib/index.esm.js CHANGED
@@ -127,10 +127,18 @@ function normalizeRemoteItem(key, remote) {
127
127
  entryGlobalName: key
128
128
  }, remote);
129
129
  }
130
+ function removePathFromNpmPackage(packageString) {
131
+ // 匹配npm包名的正则表达式,忽略路径部分
132
+ var regex = /^(?:@[^/]+\/)?[^/]+/;
133
+ // 使用正则表达式匹配并提取包名
134
+ var match = packageString.match(regex);
135
+ // 返回匹配到的包名,如果没有匹配到则返回原字符串
136
+ return match ? match[0] : packageString;
137
+ }
130
138
  function normalizeShareItem(key, shareItem) {
131
139
  var version;
132
140
  try {
133
- version = require(path.join(key, 'package.json')).version;
141
+ version = require(path.join(removePathFromNpmPackage(key), 'package.json')).version;
134
142
  } catch (e) {
135
143
  console.log(e);
136
144
  }
@@ -246,7 +254,7 @@ function getLoadShareModulePath(pkg) {
246
254
  return resolve(emptyNpmDir, filename);
247
255
  }
248
256
  function writeLoadShareModule(pkg, shareItem, command) {
249
- writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = 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 ");
257
+ writeFileSync(getLoadShareModulePath(pkg), "\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 res = 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 ");
250
258
  }
251
259
  function npmPackageNameToFileName(packageName) {
252
260
  // 1. 去掉包名前的 "@"
@@ -258,7 +266,7 @@ function npmPackageNameToFileName(packageName) {
258
266
  }
259
267
 
260
268
  var emptyPath = require.resolve('an-empty-js-file');
261
- var REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
269
+ var REMOTE_ENTRY_ID = 'REMOTE_ENTRY_ID';
262
270
  function generateRemoteEntry(options) {
263
271
  var pluginImportNames = options.runtimePlugins.map(function (p, i) {
264
272
  return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p + "\";"];
@@ -269,7 +277,7 @@ function generateRemoteEntry(options) {
269
277
  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 ";
270
278
  }).join(',') + "\n }\n import localSharedImportMap from \"" + getLocalSharedImportMapId() + "\"\n async function init(shared = {}) {\n const localShared = {\n " + Object.keys(options.shared).map(function (key) {
271
279
  var shareItem = options.shared[key];
272
- return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \n const res = await pkgDynamicImport()\n return function () {\n return res\n }\n },\n shareConfig: {\n singleton: " + shareItem.shareConfig.singleton + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }\n }\n ";
280
+ return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \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 ";
273
281
  }).join(',') + "\n }\n const initRes = runtimeInit({\n name: " + JSON.stringify(options.name) + ",\n remotes: [" + Object.keys(options.remotes).map(function (key) {
274
282
  var remote = options.remotes[key];
275
283
  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 ";
@@ -277,7 +285,7 @@ function generateRemoteEntry(options) {
277
285
  return item[0] + "()";
278
286
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
279
287
  }
280
- var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
288
+ var WRAP_REMOTE_ENTRY_QUERY_STR = '__mf__wrapRemoteEntry__';
281
289
  var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
282
290
  function generateWrapRemoteEntry() {
283
291
  return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
@@ -286,7 +294,7 @@ function generateWrapRemoteEntry() {
286
294
  * Inject entry file, automatically init when used as host,
287
295
  * and will not inject remoteEntry
288
296
  */
289
- var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
297
+ var HOST_AUTO_INIT_QUERY_STR = '__mf__isHostInit';
290
298
  var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
291
299
  function generateWrapHostInit() {
292
300
  return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
@@ -134,10 +134,18 @@ function normalizeRemoteItem(key, remote) {
134
134
  entryGlobalName: key
135
135
  }, remote);
136
136
  }
137
+ function removePathFromNpmPackage(packageString) {
138
+ // 匹配npm包名的正则表达式,忽略路径部分
139
+ const regex = /^(?:@[^/]+\/)?[^/]+/;
140
+ // 使用正则表达式匹配并提取包名
141
+ const match = packageString.match(regex);
142
+ // 返回匹配到的包名,如果没有匹配到则返回原字符串
143
+ return match ? match[0] : packageString;
144
+ }
137
145
  function normalizeShareItem(key, shareItem) {
138
146
  let version;
139
147
  try {
140
- version = require(path.join(key, 'package.json')).version;
148
+ version = require(path.join(removePathFromNpmPackage(key), 'package.json')).version;
141
149
  } catch (e) {
142
150
  console.log(e);
143
151
  }
@@ -263,6 +271,8 @@ function getLoadShareModulePath(pkg) {
263
271
  }
264
272
  function writeLoadShareModule(pkg, shareItem, command) {
265
273
  writeFileSync(getLoadShareModulePath(pkg), `
274
+ // dev uses dynamic import to separate chunks
275
+ ${command !== "build" ? `;() => import(${JSON.stringify(pkg)}).catch(() => {});` : ''}
266
276
  const {loadShare} = require("@module-federation/runtime")
267
277
  const res = loadShare(${JSON.stringify(pkg)}, {
268
278
  customShareInfo: {shareConfig:{
@@ -284,7 +294,7 @@ function npmPackageNameToFileName(packageName) {
284
294
  }
285
295
 
286
296
  const emptyPath = require.resolve('an-empty-js-file');
287
- const REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
297
+ const REMOTE_ENTRY_ID = 'REMOTE_ENTRY_ID';
288
298
  function generateRemoteEntry(options) {
289
299
  const pluginImportNames = options.runtimePlugins.map((p, i) => [`$runtimePlugin_${i}`, `import $runtimePlugin_${i} from "${p}";`]);
290
300
  return `
@@ -324,8 +334,14 @@ function generateRemoteEntry(options) {
324
334
  localShared[${JSON.stringify(key)}].loaded = true
325
335
  const {${JSON.stringify(key)}: pkgDynamicImport} = localSharedImportMap
326
336
  const res = await pkgDynamicImport()
337
+ const exportModule = {...res}
338
+ // All npm packages pre-built by vite will be converted to esm
339
+ Object.defineProperty(exportModule, "__esModule", {
340
+ value: true,
341
+ enumerable: false
342
+ })
327
343
  return function () {
328
- return res
344
+ return exportModule
329
345
  }
330
346
  },
331
347
  shareConfig: {
@@ -367,7 +383,7 @@ function generateRemoteEntry(options) {
367
383
  }
368
384
  `;
369
385
  }
370
- const WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
386
+ const WRAP_REMOTE_ENTRY_QUERY_STR = '__mf__wrapRemoteEntry__';
371
387
  const WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
372
388
  function generateWrapRemoteEntry() {
373
389
  return `
@@ -379,7 +395,7 @@ function generateWrapRemoteEntry() {
379
395
  * Inject entry file, automatically init when used as host,
380
396
  * and will not inject remoteEntry
381
397
  */
382
- const HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
398
+ const HOST_AUTO_INIT_QUERY_STR = '__mf__isHostInit';
383
399
  const HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
384
400
  function generateWrapHostInit() {
385
401
  return `
package/lib/index.umd.js CHANGED
@@ -148,10 +148,18 @@
148
148
  entryGlobalName: key
149
149
  }, remote);
150
150
  }
151
+ function removePathFromNpmPackage(packageString) {
152
+ // 匹配npm包名的正则表达式,忽略路径部分
153
+ var regex = /^(?:@[^/]+\/)?[^/]+/;
154
+ // 使用正则表达式匹配并提取包名
155
+ var match = packageString.match(regex);
156
+ // 返回匹配到的包名,如果没有匹配到则返回原字符串
157
+ return match ? match[0] : packageString;
158
+ }
151
159
  function normalizeShareItem(key, shareItem) {
152
160
  var version;
153
161
  try {
154
- version = require(path__namespace.join(key, 'package.json')).version;
162
+ version = require(path__namespace.join(removePathFromNpmPackage(key), 'package.json')).version;
155
163
  } catch (e) {
156
164
  console.log(e);
157
165
  }
@@ -267,7 +275,7 @@
267
275
  return path.resolve(emptyNpmDir, filename);
268
276
  }
269
277
  function writeLoadShareModule(pkg, shareItem, command) {
270
- fs.writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = 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 ");
278
+ fs.writeFileSync(getLoadShareModulePath(pkg), "\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 res = 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 ");
271
279
  }
272
280
  function npmPackageNameToFileName(packageName) {
273
281
  // 1. 去掉包名前的 "@"
@@ -279,7 +287,7 @@
279
287
  }
280
288
 
281
289
  var emptyPath = require.resolve('an-empty-js-file');
282
- var REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
290
+ var REMOTE_ENTRY_ID = 'REMOTE_ENTRY_ID';
283
291
  function generateRemoteEntry(options) {
284
292
  var pluginImportNames = options.runtimePlugins.map(function (p, i) {
285
293
  return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p + "\";"];
@@ -290,7 +298,7 @@
290
298
  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 ";
291
299
  }).join(',') + "\n }\n import localSharedImportMap from \"" + getLocalSharedImportMapId() + "\"\n async function init(shared = {}) {\n const localShared = {\n " + Object.keys(options.shared).map(function (key) {
292
300
  var shareItem = options.shared[key];
293
- return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \n const res = await pkgDynamicImport()\n return function () {\n return res\n }\n },\n shareConfig: {\n singleton: " + shareItem.shareConfig.singleton + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }\n }\n ";
301
+ return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(shareItem.name) + ",\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 localShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = localSharedImportMap \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 ";
294
302
  }).join(',') + "\n }\n const initRes = runtimeInit({\n name: " + JSON.stringify(options.name) + ",\n remotes: [" + Object.keys(options.remotes).map(function (key) {
295
303
  var remote = options.remotes[key];
296
304
  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 ";
@@ -298,7 +306,7 @@
298
306
  return item[0] + "()";
299
307
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
300
308
  }
301
- var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
309
+ var WRAP_REMOTE_ENTRY_QUERY_STR = '__mf__wrapRemoteEntry__';
302
310
  var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
303
311
  function generateWrapRemoteEntry() {
304
312
  return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
@@ -307,7 +315,7 @@
307
315
  * Inject entry file, automatically init when used as host,
308
316
  * and will not inject remoteEntry
309
317
  */
310
- var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
318
+ var HOST_AUTO_INIT_QUERY_STR = '__mf__isHostInit';
311
319
  var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
312
320
  function generateWrapHostInit() {
313
321
  return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
@@ -1,4 +1,4 @@
1
- import { NormalizedModuleFederationOptions } from "../utils/normalizeModuleFederationOptions";
1
+ import { NormalizedModuleFederationOptions } from '../utils/normalizeModuleFederationOptions';
2
2
  export declare const REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
3
3
  export declare function generateRemoteEntry(options: NormalizedModuleFederationOptions): string;
4
4
  export declare const WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.0.0-alpha-def937d",
3
+ "version": "1.0.0-alpha-6cae9ab",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",