@module-federation/vite 1.13.3 → 1.13.4
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 +35 -5
- package/lib/index.mjs +35 -5
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -746,7 +746,7 @@ function inferVersionFromRequiredVersion(requiredVersion) {
|
|
|
746
746
|
}
|
|
747
747
|
function normalizeShareItem(key, shareItem) {
|
|
748
748
|
let version;
|
|
749
|
-
try {
|
|
749
|
+
if (!(typeof shareItem === "object" && shareItem.import === false)) try {
|
|
750
750
|
try {
|
|
751
751
|
version = require(pathe.join(removePathFromNpmPackage(key), "package.json")).version;
|
|
752
752
|
} catch (e1) {
|
|
@@ -1386,6 +1386,28 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
|
|
|
1386
1386
|
const importLine = command === "build" ? getRuntimeInitPromiseBootstrapCode() : useESM ? `${getRuntimeInitBootstrapCode()}
|
|
1387
1387
|
const { initPromise } = globalThis[globalKey];` : `const {initPromise} = require("${virtualRuntimeInitStatus.getImportId()}")`;
|
|
1388
1388
|
const awaitOrPlaceholder = useESM ? "await " : "/*mf top-level-await placeholder replacement mf*/";
|
|
1389
|
+
if (shareItem.shareConfig.import === false) {
|
|
1390
|
+
const namedExports = useESM ? getPackageNamedExports(pkg) : [];
|
|
1391
|
+
let exportLine;
|
|
1392
|
+
if (useESM && namedExports.length > 0) exportLine = `export default exportModule.default ?? exportModule;\n ${`const { ${namedExports.map((name, i) => `${name}: __mf_${i}`).join(", ")} } = exportModule;`}\n ${`export { ${namedExports.map((name, i) => `__mf_${i} as ${name}`).join(", ")} };`}`;
|
|
1393
|
+
else {
|
|
1394
|
+
if (useESM) mfWarn(`Shared dependency "${pkg}" has import: false but is not installed locally.\n Named imports (e.g. import { ... } from '${pkg}') will not work in production builds.\n Install it as a devDependency to enable named export detection.`);
|
|
1395
|
+
exportLine = useESM ? "export default exportModule.default ?? exportModule" : "module.exports = exportModule";
|
|
1396
|
+
}
|
|
1397
|
+
loadShareCacheMap[pkg].writeSync(`
|
|
1398
|
+
${importLine}
|
|
1399
|
+
const res = initPromise.then(runtime => runtime.loadShare(${escapeGeneratedStringLiteral(pkg)}, {
|
|
1400
|
+
customShareInfo: {shareConfig:{
|
|
1401
|
+
singleton: ${shareItem.shareConfig.singleton},
|
|
1402
|
+
strictVersion: ${shareItem.shareConfig.strictVersion},
|
|
1403
|
+
requiredVersion: ${JSON.stringify(shareItem.shareConfig.requiredVersion)}
|
|
1404
|
+
}}
|
|
1405
|
+
}))
|
|
1406
|
+
const exportModule = ${awaitOrPlaceholder}res.then((factory) => (typeof factory === "function" ? factory() : factory))
|
|
1407
|
+
${exportLine}
|
|
1408
|
+
`, true);
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1389
1411
|
const useSsrProviderFallback = hasPackageDependency("vinext") && command === "build" && pkg === "react";
|
|
1390
1412
|
const concreteSharedImportSource = getConcreteSharedImportSource(pkg, shareItem);
|
|
1391
1413
|
const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg);
|
|
@@ -1533,6 +1555,14 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1533
1555
|
];
|
|
1534
1556
|
});
|
|
1535
1557
|
return `
|
|
1558
|
+
// Shim Vue HMR runtime for dev-compiled components loaded by a non-Vite host.
|
|
1559
|
+
// When a remote is served by a Vite dev server, Vue's SFC compiler injects HMR
|
|
1560
|
+
// hooks that reference __VUE_HMR_RUNTIME__. This global only exists on pages
|
|
1561
|
+
// served by Vite's client runtime. When a production host loads the remote,
|
|
1562
|
+
// the HMR calls would throw. This no-op shim prevents that.
|
|
1563
|
+
if (typeof __VUE_HMR_RUNTIME__ === 'undefined') {
|
|
1564
|
+
globalThis.__VUE_HMR_RUNTIME__ = { createRecord() {}, rerender() {}, reload() {} };
|
|
1565
|
+
}
|
|
1536
1566
|
import {init as runtimeInit, loadRemote} from "@module-federation/runtime";
|
|
1537
1567
|
${pluginImportNames.map((item) => item[1]).join("\n")}
|
|
1538
1568
|
${command === "build" ? getRuntimeInitResolveBootstrapCode() : getRuntimeInitBootstrapCode() + "\n const { initResolve } = globalThis[globalKey];"}
|
|
@@ -2278,7 +2308,7 @@ function proxySharedModule(options) {
|
|
|
2278
2308
|
if (key.endsWith("/") && source !== key.slice(0, -1)) return;
|
|
2279
2309
|
const loadSharePath = getLoadShareModulePath(source, isRolldown, command);
|
|
2280
2310
|
writeLoadShareModule(source, shared[key], command, isRolldown);
|
|
2281
|
-
writePreBuildLibPath(source, shared[key]);
|
|
2311
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(source, shared[key]);
|
|
2282
2312
|
addUsedShares(source);
|
|
2283
2313
|
writeLocalSharedImportMap();
|
|
2284
2314
|
return this.resolve(loadSharePath, importer);
|
|
@@ -2317,7 +2347,7 @@ function proxySharedModule(options) {
|
|
|
2317
2347
|
return;
|
|
2318
2348
|
}
|
|
2319
2349
|
writeLoadShareModule(key, shared[key], _command, isRolldown);
|
|
2320
|
-
writePreBuildLibPath(key, shared[key]);
|
|
2350
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(key, shared[key]);
|
|
2321
2351
|
addUsedShares(key);
|
|
2322
2352
|
});
|
|
2323
2353
|
writeLocalSharedImportMap();
|
|
@@ -2545,9 +2575,9 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
2545
2575
|
}
|
|
2546
2576
|
getLoadShareModulePath(key, isRolldown);
|
|
2547
2577
|
writeLoadShareModule(key, shareItem, _command, isRolldown);
|
|
2548
|
-
writePreBuildLibPath(key, shareItem);
|
|
2578
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(key, shareItem);
|
|
2549
2579
|
addUsedShares(key);
|
|
2550
|
-
if (_command === "serve") {
|
|
2580
|
+
if (_command === "serve" && shareItem.shareConfig?.import !== false) {
|
|
2551
2581
|
if (!isRolldown) config.optimizeDeps.include.push(getLoadShareImportId(key, isRolldown, _command));
|
|
2552
2582
|
config.optimizeDeps.include.push(getPreBuildLibImportId(key));
|
|
2553
2583
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -724,7 +724,7 @@ function inferVersionFromRequiredVersion(requiredVersion) {
|
|
|
724
724
|
}
|
|
725
725
|
function normalizeShareItem(key, shareItem) {
|
|
726
726
|
let version;
|
|
727
|
-
try {
|
|
727
|
+
if (!(typeof shareItem === "object" && shareItem.import === false)) try {
|
|
728
728
|
try {
|
|
729
729
|
version = __require(path$1.join(removePathFromNpmPackage(key), "package.json")).version;
|
|
730
730
|
} catch (e1) {
|
|
@@ -1363,6 +1363,28 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
|
|
|
1363
1363
|
const importLine = command === "build" ? getRuntimeInitPromiseBootstrapCode() : useESM ? `${getRuntimeInitBootstrapCode()}
|
|
1364
1364
|
const { initPromise } = globalThis[globalKey];` : `const {initPromise} = require("${virtualRuntimeInitStatus.getImportId()}")`;
|
|
1365
1365
|
const awaitOrPlaceholder = useESM ? "await " : "/*mf top-level-await placeholder replacement mf*/";
|
|
1366
|
+
if (shareItem.shareConfig.import === false) {
|
|
1367
|
+
const namedExports = useESM ? getPackageNamedExports(pkg) : [];
|
|
1368
|
+
let exportLine;
|
|
1369
|
+
if (useESM && namedExports.length > 0) exportLine = `export default exportModule.default ?? exportModule;\n ${`const { ${namedExports.map((name, i) => `${name}: __mf_${i}`).join(", ")} } = exportModule;`}\n ${`export { ${namedExports.map((name, i) => `__mf_${i} as ${name}`).join(", ")} };`}`;
|
|
1370
|
+
else {
|
|
1371
|
+
if (useESM) mfWarn(`Shared dependency "${pkg}" has import: false but is not installed locally.\n Named imports (e.g. import { ... } from '${pkg}') will not work in production builds.\n Install it as a devDependency to enable named export detection.`);
|
|
1372
|
+
exportLine = useESM ? "export default exportModule.default ?? exportModule" : "module.exports = exportModule";
|
|
1373
|
+
}
|
|
1374
|
+
loadShareCacheMap[pkg].writeSync(`
|
|
1375
|
+
${importLine}
|
|
1376
|
+
const res = initPromise.then(runtime => runtime.loadShare(${escapeGeneratedStringLiteral(pkg)}, {
|
|
1377
|
+
customShareInfo: {shareConfig:{
|
|
1378
|
+
singleton: ${shareItem.shareConfig.singleton},
|
|
1379
|
+
strictVersion: ${shareItem.shareConfig.strictVersion},
|
|
1380
|
+
requiredVersion: ${JSON.stringify(shareItem.shareConfig.requiredVersion)}
|
|
1381
|
+
}}
|
|
1382
|
+
}))
|
|
1383
|
+
const exportModule = ${awaitOrPlaceholder}res.then((factory) => (typeof factory === "function" ? factory() : factory))
|
|
1384
|
+
${exportLine}
|
|
1385
|
+
`, true);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1366
1388
|
const useSsrProviderFallback = hasPackageDependency("vinext") && command === "build" && pkg === "react";
|
|
1367
1389
|
const concreteSharedImportSource = getConcreteSharedImportSource(pkg, shareItem);
|
|
1368
1390
|
const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg);
|
|
@@ -1510,6 +1532,14 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1510
1532
|
];
|
|
1511
1533
|
});
|
|
1512
1534
|
return `
|
|
1535
|
+
// Shim Vue HMR runtime for dev-compiled components loaded by a non-Vite host.
|
|
1536
|
+
// When a remote is served by a Vite dev server, Vue's SFC compiler injects HMR
|
|
1537
|
+
// hooks that reference __VUE_HMR_RUNTIME__. This global only exists on pages
|
|
1538
|
+
// served by Vite's client runtime. When a production host loads the remote,
|
|
1539
|
+
// the HMR calls would throw. This no-op shim prevents that.
|
|
1540
|
+
if (typeof __VUE_HMR_RUNTIME__ === 'undefined') {
|
|
1541
|
+
globalThis.__VUE_HMR_RUNTIME__ = { createRecord() {}, rerender() {}, reload() {} };
|
|
1542
|
+
}
|
|
1513
1543
|
import {init as runtimeInit, loadRemote} from "@module-federation/runtime";
|
|
1514
1544
|
${pluginImportNames.map((item) => item[1]).join("\n")}
|
|
1515
1545
|
${command === "build" ? getRuntimeInitResolveBootstrapCode() : getRuntimeInitBootstrapCode() + "\n const { initResolve } = globalThis[globalKey];"}
|
|
@@ -2255,7 +2285,7 @@ function proxySharedModule(options) {
|
|
|
2255
2285
|
if (key.endsWith("/") && source !== key.slice(0, -1)) return;
|
|
2256
2286
|
const loadSharePath = getLoadShareModulePath(source, isRolldown, command);
|
|
2257
2287
|
writeLoadShareModule(source, shared[key], command, isRolldown);
|
|
2258
|
-
writePreBuildLibPath(source, shared[key]);
|
|
2288
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(source, shared[key]);
|
|
2259
2289
|
addUsedShares(source);
|
|
2260
2290
|
writeLocalSharedImportMap();
|
|
2261
2291
|
return this.resolve(loadSharePath, importer);
|
|
@@ -2294,7 +2324,7 @@ function proxySharedModule(options) {
|
|
|
2294
2324
|
return;
|
|
2295
2325
|
}
|
|
2296
2326
|
writeLoadShareModule(key, shared[key], _command, isRolldown);
|
|
2297
|
-
writePreBuildLibPath(key, shared[key]);
|
|
2327
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(key, shared[key]);
|
|
2298
2328
|
addUsedShares(key);
|
|
2299
2329
|
});
|
|
2300
2330
|
writeLocalSharedImportMap();
|
|
@@ -2522,9 +2552,9 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
2522
2552
|
}
|
|
2523
2553
|
getLoadShareModulePath(key, isRolldown);
|
|
2524
2554
|
writeLoadShareModule(key, shareItem, _command, isRolldown);
|
|
2525
|
-
writePreBuildLibPath(key, shareItem);
|
|
2555
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(key, shareItem);
|
|
2526
2556
|
addUsedShares(key);
|
|
2527
|
-
if (_command === "serve") {
|
|
2557
|
+
if (_command === "serve" && shareItem.shareConfig?.import !== false) {
|
|
2528
2558
|
if (!isRolldown) config.optimizeDeps.include.push(getLoadShareImportId(key, isRolldown, _command));
|
|
2529
2559
|
config.optimizeDeps.include.push(getPreBuildLibImportId(key));
|
|
2530
2560
|
}
|