@module-federation/vite 1.13.6 → 1.13.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 CHANGED
@@ -19,6 +19,7 @@ Examples live in [`gioboa/module-federation-vite-examples`](https://github.com/g
19
19
  | [Angular](https://github.com/gioboa/module-federation-vite-examples/tree/main/angular) | `angular-host` | `angular-remote` | Angular |
20
20
  | [Lit](https://github.com/gioboa/module-federation-vite-examples/tree/main/lit) | `lit-host` | `lit-remote` | Lit |
21
21
  | [Nuxt](https://github.com/gioboa/module-federation-vite-examples/tree/main/nuxt) | `nuxt-host` | `nuxt-remote` | Nuxt 4 |
22
+ | [Preact](https://github.com/gioboa/module-federation-vite-examples/tree/main/preact) | `preact-host` | `preact-remote` | Preact 10 |
22
23
  | [React](https://github.com/gioboa/module-federation-vite-examples/tree/main/react) | `react-host` | `react-remote` | React 19 |
23
24
  | [Solid](https://github.com/gioboa/module-federation-vite-examples/tree/main/solid) | `solid-host` | `solid-remote` | Solid |
24
25
  | [Svelte](https://github.com/gioboa/module-federation-vite-examples/tree/main/svelte) | `svelte-host` | `svelte-remote` | Svelte 5 |
package/lib/index.cjs CHANGED
@@ -28,6 +28,7 @@ fs = __toESM(fs);
28
28
  let module$1 = require("module");
29
29
  let pathe = require("pathe");
30
30
  pathe = __toESM(pathe);
31
+ let vite = require("vite");
31
32
  let magic_string = require("magic-string");
32
33
  magic_string = __toESM(magic_string);
33
34
  let _rollup_pluginutils = require("@rollup/pluginutils");
@@ -227,17 +228,21 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
227
228
  next();
228
229
  });
229
230
  },
230
- transformIndexHtml(c) {
231
- if (!injectHtml()) return;
232
- clientInjected = true;
233
- const html = rewriteEntryScripts(c, (originalSrc) => {
234
- const query = new URLSearchParams({
235
- init: sanitizeDevEntryPath(devEntryPath),
236
- entry: originalSrc
237
- }).toString();
238
- return `${viteConfig.base}@id/${DEV_HTML_PROXY_PREFIX}${query}`;
239
- });
240
- return html === c ? injectEntryScript(c, devEntryPath) : html;
231
+ transformIndexHtml: {
232
+ order: "pre",
233
+ handler(c) {
234
+ if (!injectHtml()) return;
235
+ clientInjected = true;
236
+ const base = viteConfig.base.replace(/\/$/, "");
237
+ const stripBase = (p) => base && p.startsWith(base) ? p.slice(base.length) : p;
238
+ const html = rewriteEntryScripts(c, (originalSrc) => {
239
+ return `/@id/${DEV_HTML_PROXY_PREFIX}${new URLSearchParams({
240
+ init: sanitizeDevEntryPath(stripBase(devEntryPath)),
241
+ entry: originalSrc
242
+ }).toString()}`;
243
+ });
244
+ return html === c ? injectEntryScript(c, stripBase(devEntryPath)) : html;
245
+ }
241
246
  },
242
247
  resolveId(id) {
243
248
  if (id.startsWith(DEV_HTML_PROXY_PREFIX)) return id;
@@ -1236,6 +1241,10 @@ function escapeGeneratedStringLiteral(value) {
1236
1241
  function isValidJsIdentifier(name) {
1237
1242
  return /^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u.test(name);
1238
1243
  }
1244
+ function isValidEsmExportName(name) {
1245
+ return !!name && name !== "default" && name !== "__esModule" && isValidJsIdentifier(name);
1246
+ }
1247
+ const JS_IDENTIFIER_PATTERN = `[\$_\\p{ID_Start}][\$_\\u200C\\u200D\\p{ID_Continue}]*`;
1239
1248
  const localRequire = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
1240
1249
  function resolvePackageEntryFromProjectRoot(pkg) {
1241
1250
  try {
@@ -1313,21 +1322,51 @@ function getPackageEsmEntryPath(pkg) {
1313
1322
  }
1314
1323
  }
1315
1324
  function getEsmNamedExports(pkg) {
1325
+ let source = "";
1316
1326
  try {
1317
1327
  const entryPath = getPackageEsmEntryPath(pkg);
1318
1328
  if (!entryPath) return [];
1319
1329
  const { initSync, parse } = localRequire("es-module-lexer");
1320
1330
  initSync();
1321
- const [, exports] = parse((0, fs.readFileSync)(entryPath, "utf-8"), entryPath);
1322
- return exports.map((item) => item.n).filter((name) => !!name && name !== "default" && name !== "__esModule" && isValidJsIdentifier(name));
1331
+ source = (0, fs.readFileSync)(entryPath, "utf-8");
1332
+ const [, exports] = parse(source, entryPath);
1333
+ const names = exports.map((item) => item.n).filter((name) => isValidEsmExportName(name));
1334
+ const regexNames = getNamedExportsViaRegex(source);
1335
+ const filteredNames = names.filter((name) => name !== "type" || regexNames.includes(name));
1336
+ if (filteredNames.length > 0) return [...new Set([...filteredNames, ...regexNames])];
1337
+ return regexNames;
1323
1338
  } catch {
1324
- return [];
1339
+ return source ? getNamedExportsViaRegex(source) : [];
1325
1340
  }
1326
1341
  }
1342
+ function getNamedExportsViaRegex(source) {
1343
+ const names = /* @__PURE__ */ new Set();
1344
+ const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
1345
+ let match;
1346
+ while ((match = declRegex.exec(source)) !== null) {
1347
+ const name = match[1];
1348
+ if (isValidEsmExportName(name)) names.add(name);
1349
+ }
1350
+ const listRegex = /export\s*\{([^}]+)\}/g;
1351
+ const typeOnlySpecifierRegex = new RegExp(`^type\\s+${JS_IDENTIFIER_PATTERN}(?:\\s+as\\s+${JS_IDENTIFIER_PATTERN})?$`, "u");
1352
+ const exportSpecifierRegex = new RegExp(`(?:\\S+\\s+as\\s+)?(${JS_IDENTIFIER_PATTERN})$`, "u");
1353
+ while ((match = listRegex.exec(source)) !== null) {
1354
+ const specifiers = match[1].split(",");
1355
+ for (const specifier of specifiers) {
1356
+ const trimmed = specifier.trim();
1357
+ if (typeOnlySpecifierRegex.test(trimmed)) continue;
1358
+ const asMatch = trimmed.match(exportSpecifierRegex);
1359
+ if (!asMatch) continue;
1360
+ const name = asMatch[1];
1361
+ if (isValidEsmExportName(name)) names.add(name);
1362
+ }
1363
+ }
1364
+ return [...names];
1365
+ }
1327
1366
  function getPackageNamedExports(pkg) {
1328
1367
  try {
1329
1368
  const mod = (0, module$1.createRequire)(new URL(`file://${pathe.default.join(getPackageDetectionCwd(), "package.json")}`))(pkg);
1330
- return Object.keys(mod).filter((k) => k !== "default" && k !== "__esModule" && isValidJsIdentifier(k));
1369
+ return Object.keys(mod).filter((k) => isValidEsmExportName(k));
1331
1370
  } catch {
1332
1371
  return getEsmNamedExports(pkg);
1333
1372
  }
@@ -1335,11 +1374,14 @@ function getPackageNamedExports(pkg) {
1335
1374
  function getLocalProviderImportPath(pkg) {
1336
1375
  try {
1337
1376
  const resolved = (0, module$1.createRequire)(new URL(`file://${pathe.default.join(getPackageDetectionCwd(), "package.json")}`)).resolve(pkg);
1338
- return resolved.includes("/node_modules/") || resolved.includes("\\node_modules\\") ? void 0 : resolved;
1377
+ return isWorkspaceFilePath(resolved) ? resolved : void 0;
1339
1378
  } catch {
1340
1379
  return;
1341
1380
  }
1342
1381
  }
1382
+ function isWorkspaceFilePath(resolved) {
1383
+ return !!resolved && !resolved.includes("/node_modules/") && !resolved.includes("\\node_modules\\");
1384
+ }
1343
1385
  function tryResolveImportFromPackageRoot(pkg, root) {
1344
1386
  try {
1345
1387
  return (0, module$1.createRequire)(new URL(`file://${pathe.default.join(root, "package.json")}`)).resolve(pkg);
@@ -1422,7 +1464,9 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
1422
1464
  const concreteSharedImportSource = getConcreteSharedImportSource(pkg, shareItem);
1423
1465
  const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg);
1424
1466
  const devImportSource = concreteSharedImportSource || pkg;
1425
- const providerImportId = getLocalProviderImportPath(pkg) || concreteSharedImportSource || sharedImportSource;
1467
+ const localProviderPath = getLocalProviderImportPath(pkg);
1468
+ const isWorkspacePackage = isWorkspaceFilePath(localProviderPath) || isWorkspaceFilePath(concreteSharedImportSource);
1469
+ const providerImportId = localProviderPath || concreteSharedImportSource || sharedImportSource;
1426
1470
  const namedExports = getPackageNamedExports(pkg);
1427
1471
  let exportLine;
1428
1472
  if (namedExports.length > 0) {
@@ -1430,9 +1474,11 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
1430
1474
  const namedExportLine = `export { ${namedExports.map((name, i) => `__mf_${i} as ${name}`).join(", ")} };`;
1431
1475
  exportLine = useESM ? `export default exportModule.default ?? exportModule;\n ${destructure}\n ${namedExportLine}` : `module.exports = exportModule;\n ${destructure}\n Object.assign(module.exports, { ${namedExports.map((name, i) => `"${name}": __mf_${i}`).join(", ")} });`;
1432
1476
  } else exportLine = useESM ? `export default exportModule.default ?? exportModule\n export * from ${escapeGeneratedStringLiteral(sharedImportSource)}` : "module.exports = exportModule";
1477
+ const prebuildImportLine = isWorkspacePackage && command !== "build" ? "" : `import ${escapeGeneratedStringLiteral(sharedImportSource)};`;
1478
+ const devDynamicImportLine = isWorkspacePackage ? "" : command !== "build" ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : "";
1433
1479
  loadShareCacheMap[pkg].writeSync(`
1434
- import ${escapeGeneratedStringLiteral(sharedImportSource)};
1435
- ${command !== "build" ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : ""}
1480
+ ${prebuildImportLine}
1481
+ ${devDynamicImportLine}
1436
1482
  ${importLine}
1437
1483
  ${useSsrProviderFallback ? `const providerModulePromise = typeof window === "undefined"
1438
1484
  ? import(${escapeGeneratedStringLiteral(providerImportId)})
@@ -2991,6 +3037,7 @@ function federation(mfUserOptions) {
2991
3037
  const remoteEntryId = getRemoteEntryId(options);
2992
3038
  const virtualExposesId = getVirtualExposesId(options);
2993
3039
  let command;
3040
+ let depsDir = "/node_modules/.vite/deps/";
2994
3041
  return [
2995
3042
  createEarlyVirtualModulesPlugin(options),
2996
3043
  ...isVinext ? [{
@@ -3018,6 +3065,11 @@ function federation(mfUserOptions) {
3018
3065
  },
3019
3066
  configResolved(config) {
3020
3067
  VirtualModule.setRoot(config.root);
3068
+ const cacheDir = config.cacheDir;
3069
+ if (cacheDir) {
3070
+ const resolved = pathe.default.isAbsolute(cacheDir) ? cacheDir : pathe.default.resolve(config.root, cacheDir);
3071
+ depsDir = (0, vite.normalizePath)(pathe.default.join(resolved, "deps")) + "/";
3072
+ } else depsDir = (0, vite.normalizePath)(pathe.default.join(config.root, "node_modules", ".vite", "deps")) + "/";
3021
3073
  VirtualModule.ensureVirtualPackageExists();
3022
3074
  initVirtualModules(command, remoteEntryId);
3023
3075
  }
@@ -3282,7 +3334,7 @@ function federation(mfUserOptions) {
3282
3334
  apply: "serve",
3283
3335
  enforce: "post",
3284
3336
  transform(code, id) {
3285
- if (!id.includes(".vite/deps/")) return;
3337
+ if (!(0, vite.normalizePath)(id).split("?")[0].startsWith(depsDir)) return;
3286
3338
  const initPattern = /\b(init_\w+__loadShare__\w+)\b/g;
3287
3339
  const initFns = /* @__PURE__ */ new Set();
3288
3340
  let match;
package/lib/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { sharePlugin } from "@module-federation/sdk";
2
1
  import { Plugin } from "vite";
2
+ import { sharePlugin } from "@module-federation/sdk";
3
3
  import { ShareStrategy } from "@module-federation/runtime/types";
4
4
 
5
5
  //#region src/utils/normalizeModuleFederationOptions.d.ts
package/lib/index.mjs CHANGED
@@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync, writeFile, writeFileSync } from "f
5
5
  import { createRequire as createRequire$1 } from "module";
6
6
  import * as path$1 from "pathe";
7
7
  import path, { basename, dirname, join, parse, resolve } from "pathe";
8
+ import { normalizePath } from "vite";
8
9
  import MagicString from "magic-string";
9
10
  import { createFilter } from "@rollup/pluginutils";
10
11
  import { normalizeOptions } from "@module-federation/sdk";
@@ -205,17 +206,21 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
205
206
  next();
206
207
  });
207
208
  },
208
- transformIndexHtml(c) {
209
- if (!injectHtml()) return;
210
- clientInjected = true;
211
- const html = rewriteEntryScripts(c, (originalSrc) => {
212
- const query = new URLSearchParams({
213
- init: sanitizeDevEntryPath(devEntryPath),
214
- entry: originalSrc
215
- }).toString();
216
- return `${viteConfig.base}@id/${DEV_HTML_PROXY_PREFIX}${query}`;
217
- });
218
- return html === c ? injectEntryScript(c, devEntryPath) : html;
209
+ transformIndexHtml: {
210
+ order: "pre",
211
+ handler(c) {
212
+ if (!injectHtml()) return;
213
+ clientInjected = true;
214
+ const base = viteConfig.base.replace(/\/$/, "");
215
+ const stripBase = (p) => base && p.startsWith(base) ? p.slice(base.length) : p;
216
+ const html = rewriteEntryScripts(c, (originalSrc) => {
217
+ return `/@id/${DEV_HTML_PROXY_PREFIX}${new URLSearchParams({
218
+ init: sanitizeDevEntryPath(stripBase(devEntryPath)),
219
+ entry: originalSrc
220
+ }).toString()}`;
221
+ });
222
+ return html === c ? injectEntryScript(c, stripBase(devEntryPath)) : html;
223
+ }
219
224
  },
220
225
  resolveId(id) {
221
226
  if (id.startsWith(DEV_HTML_PROXY_PREFIX)) return id;
@@ -1213,6 +1218,10 @@ function escapeGeneratedStringLiteral(value) {
1213
1218
  function isValidJsIdentifier(name) {
1214
1219
  return /^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u.test(name);
1215
1220
  }
1221
+ function isValidEsmExportName(name) {
1222
+ return !!name && name !== "default" && name !== "__esModule" && isValidJsIdentifier(name);
1223
+ }
1224
+ const JS_IDENTIFIER_PATTERN = `[\$_\\p{ID_Start}][\$_\\u200C\\u200D\\p{ID_Continue}]*`;
1216
1225
  const localRequire = createRequire$1(import.meta.url);
1217
1226
  function resolvePackageEntryFromProjectRoot(pkg) {
1218
1227
  try {
@@ -1290,21 +1299,51 @@ function getPackageEsmEntryPath(pkg) {
1290
1299
  }
1291
1300
  }
1292
1301
  function getEsmNamedExports(pkg) {
1302
+ let source = "";
1293
1303
  try {
1294
1304
  const entryPath = getPackageEsmEntryPath(pkg);
1295
1305
  if (!entryPath) return [];
1296
1306
  const { initSync, parse } = localRequire("es-module-lexer");
1297
1307
  initSync();
1298
- const [, exports] = parse(readFileSync(entryPath, "utf-8"), entryPath);
1299
- return exports.map((item) => item.n).filter((name) => !!name && name !== "default" && name !== "__esModule" && isValidJsIdentifier(name));
1308
+ source = readFileSync(entryPath, "utf-8");
1309
+ const [, exports] = parse(source, entryPath);
1310
+ const names = exports.map((item) => item.n).filter((name) => isValidEsmExportName(name));
1311
+ const regexNames = getNamedExportsViaRegex(source);
1312
+ const filteredNames = names.filter((name) => name !== "type" || regexNames.includes(name));
1313
+ if (filteredNames.length > 0) return [...new Set([...filteredNames, ...regexNames])];
1314
+ return regexNames;
1300
1315
  } catch {
1301
- return [];
1316
+ return source ? getNamedExportsViaRegex(source) : [];
1302
1317
  }
1303
1318
  }
1319
+ function getNamedExportsViaRegex(source) {
1320
+ const names = /* @__PURE__ */ new Set();
1321
+ const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
1322
+ let match;
1323
+ while ((match = declRegex.exec(source)) !== null) {
1324
+ const name = match[1];
1325
+ if (isValidEsmExportName(name)) names.add(name);
1326
+ }
1327
+ const listRegex = /export\s*\{([^}]+)\}/g;
1328
+ const typeOnlySpecifierRegex = new RegExp(`^type\\s+${JS_IDENTIFIER_PATTERN}(?:\\s+as\\s+${JS_IDENTIFIER_PATTERN})?$`, "u");
1329
+ const exportSpecifierRegex = new RegExp(`(?:\\S+\\s+as\\s+)?(${JS_IDENTIFIER_PATTERN})$`, "u");
1330
+ while ((match = listRegex.exec(source)) !== null) {
1331
+ const specifiers = match[1].split(",");
1332
+ for (const specifier of specifiers) {
1333
+ const trimmed = specifier.trim();
1334
+ if (typeOnlySpecifierRegex.test(trimmed)) continue;
1335
+ const asMatch = trimmed.match(exportSpecifierRegex);
1336
+ if (!asMatch) continue;
1337
+ const name = asMatch[1];
1338
+ if (isValidEsmExportName(name)) names.add(name);
1339
+ }
1340
+ }
1341
+ return [...names];
1342
+ }
1304
1343
  function getPackageNamedExports(pkg) {
1305
1344
  try {
1306
1345
  const mod = createRequire$1(new URL(`file://${path.join(getPackageDetectionCwd(), "package.json")}`))(pkg);
1307
- return Object.keys(mod).filter((k) => k !== "default" && k !== "__esModule" && isValidJsIdentifier(k));
1346
+ return Object.keys(mod).filter((k) => isValidEsmExportName(k));
1308
1347
  } catch {
1309
1348
  return getEsmNamedExports(pkg);
1310
1349
  }
@@ -1312,11 +1351,14 @@ function getPackageNamedExports(pkg) {
1312
1351
  function getLocalProviderImportPath(pkg) {
1313
1352
  try {
1314
1353
  const resolved = createRequire$1(new URL(`file://${path.join(getPackageDetectionCwd(), "package.json")}`)).resolve(pkg);
1315
- return resolved.includes("/node_modules/") || resolved.includes("\\node_modules\\") ? void 0 : resolved;
1354
+ return isWorkspaceFilePath(resolved) ? resolved : void 0;
1316
1355
  } catch {
1317
1356
  return;
1318
1357
  }
1319
1358
  }
1359
+ function isWorkspaceFilePath(resolved) {
1360
+ return !!resolved && !resolved.includes("/node_modules/") && !resolved.includes("\\node_modules\\");
1361
+ }
1320
1362
  function tryResolveImportFromPackageRoot(pkg, root) {
1321
1363
  try {
1322
1364
  return createRequire$1(new URL(`file://${path.join(root, "package.json")}`)).resolve(pkg);
@@ -1399,7 +1441,9 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
1399
1441
  const concreteSharedImportSource = getConcreteSharedImportSource(pkg, shareItem);
1400
1442
  const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg);
1401
1443
  const devImportSource = concreteSharedImportSource || pkg;
1402
- const providerImportId = getLocalProviderImportPath(pkg) || concreteSharedImportSource || sharedImportSource;
1444
+ const localProviderPath = getLocalProviderImportPath(pkg);
1445
+ const isWorkspacePackage = isWorkspaceFilePath(localProviderPath) || isWorkspaceFilePath(concreteSharedImportSource);
1446
+ const providerImportId = localProviderPath || concreteSharedImportSource || sharedImportSource;
1403
1447
  const namedExports = getPackageNamedExports(pkg);
1404
1448
  let exportLine;
1405
1449
  if (namedExports.length > 0) {
@@ -1407,9 +1451,11 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
1407
1451
  const namedExportLine = `export { ${namedExports.map((name, i) => `__mf_${i} as ${name}`).join(", ")} };`;
1408
1452
  exportLine = useESM ? `export default exportModule.default ?? exportModule;\n ${destructure}\n ${namedExportLine}` : `module.exports = exportModule;\n ${destructure}\n Object.assign(module.exports, { ${namedExports.map((name, i) => `"${name}": __mf_${i}`).join(", ")} });`;
1409
1453
  } else exportLine = useESM ? `export default exportModule.default ?? exportModule\n export * from ${escapeGeneratedStringLiteral(sharedImportSource)}` : "module.exports = exportModule";
1454
+ const prebuildImportLine = isWorkspacePackage && command !== "build" ? "" : `import ${escapeGeneratedStringLiteral(sharedImportSource)};`;
1455
+ const devDynamicImportLine = isWorkspacePackage ? "" : command !== "build" ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : "";
1410
1456
  loadShareCacheMap[pkg].writeSync(`
1411
- import ${escapeGeneratedStringLiteral(sharedImportSource)};
1412
- ${command !== "build" ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : ""}
1457
+ ${prebuildImportLine}
1458
+ ${devDynamicImportLine}
1413
1459
  ${importLine}
1414
1460
  ${useSsrProviderFallback ? `const providerModulePromise = typeof window === "undefined"
1415
1461
  ? import(${escapeGeneratedStringLiteral(providerImportId)})
@@ -2968,6 +3014,7 @@ function federation(mfUserOptions) {
2968
3014
  const remoteEntryId = getRemoteEntryId(options);
2969
3015
  const virtualExposesId = getVirtualExposesId(options);
2970
3016
  let command;
3017
+ let depsDir = "/node_modules/.vite/deps/";
2971
3018
  return [
2972
3019
  createEarlyVirtualModulesPlugin(options),
2973
3020
  ...isVinext ? [{
@@ -2995,6 +3042,11 @@ function federation(mfUserOptions) {
2995
3042
  },
2996
3043
  configResolved(config) {
2997
3044
  VirtualModule.setRoot(config.root);
3045
+ const cacheDir = config.cacheDir;
3046
+ if (cacheDir) {
3047
+ const resolved = path.isAbsolute(cacheDir) ? cacheDir : path.resolve(config.root, cacheDir);
3048
+ depsDir = normalizePath(path.join(resolved, "deps")) + "/";
3049
+ } else depsDir = normalizePath(path.join(config.root, "node_modules", ".vite", "deps")) + "/";
2998
3050
  VirtualModule.ensureVirtualPackageExists();
2999
3051
  initVirtualModules(command, remoteEntryId);
3000
3052
  }
@@ -3259,7 +3311,7 @@ function federation(mfUserOptions) {
3259
3311
  apply: "serve",
3260
3312
  enforce: "post",
3261
3313
  transform(code, id) {
3262
- if (!id.includes(".vite/deps/")) return;
3314
+ if (!normalizePath(id).split("?")[0].startsWith(depsDir)) return;
3263
3315
  const initPattern = /\b(init_\w+__loadShare__\w+)\b/g;
3264
3316
  const initFns = /* @__PURE__ */ new Set();
3265
3317
  let match;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.13.6",
3
+ "version": "1.13.7",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -70,9 +70,9 @@
70
70
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
71
71
  },
72
72
  "dependencies": {
73
- "@module-federation/dts-plugin": "2.3.0",
74
- "@module-federation/runtime": "2.3.0",
75
- "@module-federation/sdk": "2.3.0",
73
+ "@module-federation/dts-plugin": "2.3.1",
74
+ "@module-federation/runtime": "2.3.1",
75
+ "@module-federation/sdk": "2.3.1",
76
76
  "@rollup/pluginutils": "^5.3.0",
77
77
  "defu": "^6.1.4",
78
78
  "es-module-lexer": "^2.0.0",