@module-federation/vite 1.0.0-alpha-def937d → 1.0.0-alpha-10e1f83

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/lib/index.cjs CHANGED
@@ -268,7 +268,7 @@ function getLoadShareModulePath(pkg) {
268
268
  return path.resolve(emptyNpmDir, filename);
269
269
  }
270
270
  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 ");
271
+ 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
272
  }
273
273
  function npmPackageNameToFileName(packageName) {
274
274
  // 1. 去掉包名前的 "@"
package/lib/index.esm.js CHANGED
@@ -246,7 +246,7 @@ function getLoadShareModulePath(pkg) {
246
246
  return resolve(emptyNpmDir, filename);
247
247
  }
248
248
  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 ");
249
+ 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
250
  }
251
251
  function npmPackageNameToFileName(packageName) {
252
252
  // 1. 去掉包名前的 "@"
@@ -263,6 +263,8 @@ function getLoadShareModulePath(pkg) {
263
263
  }
264
264
  function writeLoadShareModule(pkg, shareItem, command) {
265
265
  writeFileSync(getLoadShareModulePath(pkg), `
266
+ // dev uses dynamic import to separate chunks
267
+ ${command !== "build" ? `;() => import(${JSON.stringify(pkg)}).catch(() => {});` : ''}
266
268
  const {loadShare} = require("@module-federation/runtime")
267
269
  const res = loadShare(${JSON.stringify(pkg)}, {
268
270
  customShareInfo: {shareConfig:{
package/lib/index.umd.js CHANGED
@@ -267,7 +267,7 @@
267
267
  return path.resolve(emptyNpmDir, filename);
268
268
  }
269
269
  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 ");
270
+ 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
271
  }
272
272
  function npmPackageNameToFileName(packageName) {
273
273
  // 1. 去掉包名前的 "@"
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-10e1f83",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",