@module-federation/vite 1.7.2 → 1.8.0
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 +28 -2
- package/lib/index.esm.js +28 -2
- package/lib/index.modern.js +29 -3
- package/lib/index.umd.js +28 -2
- package/lib/utils/__tests__/helpers.d.ts +2 -0
- package/lib/utils/__tests__/publicPath.test.d.ts +1 -0
- package/lib/utils/normalizeModuleFederationOptions.d.ts +6 -0
- package/lib/utils/publicPath.d.ts +9 -0
- package/package.json +17 -19
package/lib/index.cjs
CHANGED
|
@@ -465,6 +465,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
465
465
|
dev: options.dev,
|
|
466
466
|
dts: options.dts,
|
|
467
467
|
getPublicPath: options.getPublicPath,
|
|
468
|
+
publicPath: options.publicPath,
|
|
468
469
|
shareStrategy: options.shareStrategy || 'version-first',
|
|
469
470
|
ignoreOrigin: options.ignoreOrigin || false,
|
|
470
471
|
virtualModuleDir: options.virtualModuleDir || '__mf__virtual'
|
|
@@ -919,6 +920,30 @@ var buildFileToShareKeyMap = function buildFileToShareKeyMap(shareKeys, resolveF
|
|
|
919
920
|
}
|
|
920
921
|
};
|
|
921
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Resolves the public path for remote entries
|
|
925
|
+
* @param options - Module Federation options
|
|
926
|
+
* @param viteBase - Vite's base config value
|
|
927
|
+
* @param originalBase - Original base config before any transformations
|
|
928
|
+
* @returns The resolved public path
|
|
929
|
+
*/
|
|
930
|
+
function resolvePublicPath(options, viteBase, originalBase) {
|
|
931
|
+
// Use explicitly set publicPath if provided
|
|
932
|
+
if (options.publicPath) {
|
|
933
|
+
return options.publicPath;
|
|
934
|
+
}
|
|
935
|
+
// Handle empty original base case
|
|
936
|
+
if (originalBase === '') {
|
|
937
|
+
return 'auto';
|
|
938
|
+
}
|
|
939
|
+
// Use viteBase if available, ensuring it ends with a slash
|
|
940
|
+
if (viteBase) {
|
|
941
|
+
return viteBase.replace(/\/?$/, '/');
|
|
942
|
+
}
|
|
943
|
+
// Fallback to auto if no base is specified
|
|
944
|
+
return 'auto';
|
|
945
|
+
}
|
|
946
|
+
|
|
922
947
|
var Manifest = function Manifest() {
|
|
923
948
|
var mfOptions = getNormalizeModuleFederationOptions();
|
|
924
949
|
var name = mfOptions.name,
|
|
@@ -1034,7 +1059,7 @@ var Manifest = function Manifest() {
|
|
|
1034
1059
|
if (_command === 'serve') {
|
|
1035
1060
|
base = (config.server.origin || '') + config.base;
|
|
1036
1061
|
}
|
|
1037
|
-
publicPath =
|
|
1062
|
+
publicPath = resolvePublicPath(mfOptions, base, _originalConfigBase);
|
|
1038
1063
|
},
|
|
1039
1064
|
/**
|
|
1040
1065
|
* Generates the module federation manifest file
|
|
@@ -1300,7 +1325,8 @@ function pluginProxyRemoteEntry () {
|
|
|
1300
1325
|
if (_command === 'serve') {
|
|
1301
1326
|
var _viteConfig$server, _viteConfig$server2;
|
|
1302
1327
|
var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
|
|
1303
|
-
|
|
1328
|
+
var publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
|
|
1329
|
+
return Promise.resolve("\n const origin = (window && " + !options.ignoreOrigin + ") ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + " + publicPath + ")\n // __tla only serves as a hack for vite-plugin-top-level-await.\n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
|
|
1304
1330
|
}
|
|
1305
1331
|
return Promise.resolve(code);
|
|
1306
1332
|
}
|
package/lib/index.esm.js
CHANGED
|
@@ -441,6 +441,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
441
441
|
dev: options.dev,
|
|
442
442
|
dts: options.dts,
|
|
443
443
|
getPublicPath: options.getPublicPath,
|
|
444
|
+
publicPath: options.publicPath,
|
|
444
445
|
shareStrategy: options.shareStrategy || 'version-first',
|
|
445
446
|
ignoreOrigin: options.ignoreOrigin || false,
|
|
446
447
|
virtualModuleDir: options.virtualModuleDir || '__mf__virtual'
|
|
@@ -895,6 +896,30 @@ var buildFileToShareKeyMap = function buildFileToShareKeyMap(shareKeys, resolveF
|
|
|
895
896
|
}
|
|
896
897
|
};
|
|
897
898
|
|
|
899
|
+
/**
|
|
900
|
+
* Resolves the public path for remote entries
|
|
901
|
+
* @param options - Module Federation options
|
|
902
|
+
* @param viteBase - Vite's base config value
|
|
903
|
+
* @param originalBase - Original base config before any transformations
|
|
904
|
+
* @returns The resolved public path
|
|
905
|
+
*/
|
|
906
|
+
function resolvePublicPath(options, viteBase, originalBase) {
|
|
907
|
+
// Use explicitly set publicPath if provided
|
|
908
|
+
if (options.publicPath) {
|
|
909
|
+
return options.publicPath;
|
|
910
|
+
}
|
|
911
|
+
// Handle empty original base case
|
|
912
|
+
if (originalBase === '') {
|
|
913
|
+
return 'auto';
|
|
914
|
+
}
|
|
915
|
+
// Use viteBase if available, ensuring it ends with a slash
|
|
916
|
+
if (viteBase) {
|
|
917
|
+
return viteBase.replace(/\/?$/, '/');
|
|
918
|
+
}
|
|
919
|
+
// Fallback to auto if no base is specified
|
|
920
|
+
return 'auto';
|
|
921
|
+
}
|
|
922
|
+
|
|
898
923
|
var Manifest = function Manifest() {
|
|
899
924
|
var mfOptions = getNormalizeModuleFederationOptions();
|
|
900
925
|
var name = mfOptions.name,
|
|
@@ -1010,7 +1035,7 @@ var Manifest = function Manifest() {
|
|
|
1010
1035
|
if (_command === 'serve') {
|
|
1011
1036
|
base = (config.server.origin || '') + config.base;
|
|
1012
1037
|
}
|
|
1013
|
-
publicPath =
|
|
1038
|
+
publicPath = resolvePublicPath(mfOptions, base, _originalConfigBase);
|
|
1014
1039
|
},
|
|
1015
1040
|
/**
|
|
1016
1041
|
* Generates the module federation manifest file
|
|
@@ -1276,7 +1301,8 @@ function pluginProxyRemoteEntry () {
|
|
|
1276
1301
|
if (_command === 'serve') {
|
|
1277
1302
|
var _viteConfig$server, _viteConfig$server2;
|
|
1278
1303
|
var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
|
|
1279
|
-
|
|
1304
|
+
var publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
|
|
1305
|
+
return Promise.resolve("\n const origin = (window && " + !options.ignoreOrigin + ") ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + " + publicPath + ")\n // __tla only serves as a hack for vite-plugin-top-level-await.\n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
|
|
1280
1306
|
}
|
|
1281
1307
|
return Promise.resolve(code);
|
|
1282
1308
|
}
|
package/lib/index.modern.js
CHANGED
|
@@ -411,6 +411,7 @@ function normalizeModuleFederationOptions(options) {
|
|
|
411
411
|
dev: options.dev,
|
|
412
412
|
dts: options.dts,
|
|
413
413
|
getPublicPath: options.getPublicPath,
|
|
414
|
+
publicPath: options.publicPath,
|
|
414
415
|
shareStrategy: options.shareStrategy || 'version-first',
|
|
415
416
|
ignoreOrigin: options.ignoreOrigin || false,
|
|
416
417
|
virtualModuleDir: options.virtualModuleDir || '__mf__virtual'
|
|
@@ -971,6 +972,30 @@ const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
|
|
|
971
972
|
return fileToShareKey;
|
|
972
973
|
};
|
|
973
974
|
|
|
975
|
+
/**
|
|
976
|
+
* Resolves the public path for remote entries
|
|
977
|
+
* @param options - Module Federation options
|
|
978
|
+
* @param viteBase - Vite's base config value
|
|
979
|
+
* @param originalBase - Original base config before any transformations
|
|
980
|
+
* @returns The resolved public path
|
|
981
|
+
*/
|
|
982
|
+
function resolvePublicPath(options, viteBase, originalBase) {
|
|
983
|
+
// Use explicitly set publicPath if provided
|
|
984
|
+
if (options.publicPath) {
|
|
985
|
+
return options.publicPath;
|
|
986
|
+
}
|
|
987
|
+
// Handle empty original base case
|
|
988
|
+
if (originalBase === '') {
|
|
989
|
+
return 'auto';
|
|
990
|
+
}
|
|
991
|
+
// Use viteBase if available, ensuring it ends with a slash
|
|
992
|
+
if (viteBase) {
|
|
993
|
+
return viteBase.replace(/\/?$/, '/');
|
|
994
|
+
}
|
|
995
|
+
// Fallback to auto if no base is specified
|
|
996
|
+
return 'auto';
|
|
997
|
+
}
|
|
998
|
+
|
|
974
999
|
const Manifest = () => {
|
|
975
1000
|
const mfOptions = getNormalizeModuleFederationOptions();
|
|
976
1001
|
const {
|
|
@@ -1089,7 +1114,7 @@ const Manifest = () => {
|
|
|
1089
1114
|
if (_command === 'serve') {
|
|
1090
1115
|
base = (config.server.origin || '') + config.base;
|
|
1091
1116
|
}
|
|
1092
|
-
publicPath =
|
|
1117
|
+
publicPath = resolvePublicPath(mfOptions, base, _originalConfigBase);
|
|
1093
1118
|
},
|
|
1094
1119
|
/**
|
|
1095
1120
|
* Generates the module federation manifest file
|
|
@@ -1332,10 +1357,11 @@ function pluginProxyRemoteEntry () {
|
|
|
1332
1357
|
if (_command === 'serve') {
|
|
1333
1358
|
var _viteConfig$server, _viteConfig$server2;
|
|
1334
1359
|
const host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
|
|
1360
|
+
const publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
|
|
1335
1361
|
return `
|
|
1336
1362
|
const origin = (window && ${!options.ignoreOrigin}) ? window.origin : "//${host}:${(_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port}"
|
|
1337
|
-
const remoteEntryPromise = await import(origin +
|
|
1338
|
-
// __tla only serves as a hack for vite-plugin-top-level-await.
|
|
1363
|
+
const remoteEntryPromise = await import(origin + ${publicPath})
|
|
1364
|
+
// __tla only serves as a hack for vite-plugin-top-level-await.
|
|
1339
1365
|
Promise.resolve(remoteEntryPromise)
|
|
1340
1366
|
.then(remoteEntry => {
|
|
1341
1367
|
return Promise.resolve(remoteEntry.__tla)
|
package/lib/index.umd.js
CHANGED
|
@@ -463,6 +463,7 @@
|
|
|
463
463
|
dev: options.dev,
|
|
464
464
|
dts: options.dts,
|
|
465
465
|
getPublicPath: options.getPublicPath,
|
|
466
|
+
publicPath: options.publicPath,
|
|
466
467
|
shareStrategy: options.shareStrategy || 'version-first',
|
|
467
468
|
ignoreOrigin: options.ignoreOrigin || false,
|
|
468
469
|
virtualModuleDir: options.virtualModuleDir || '__mf__virtual'
|
|
@@ -917,6 +918,30 @@
|
|
|
917
918
|
}
|
|
918
919
|
};
|
|
919
920
|
|
|
921
|
+
/**
|
|
922
|
+
* Resolves the public path for remote entries
|
|
923
|
+
* @param options - Module Federation options
|
|
924
|
+
* @param viteBase - Vite's base config value
|
|
925
|
+
* @param originalBase - Original base config before any transformations
|
|
926
|
+
* @returns The resolved public path
|
|
927
|
+
*/
|
|
928
|
+
function resolvePublicPath(options, viteBase, originalBase) {
|
|
929
|
+
// Use explicitly set publicPath if provided
|
|
930
|
+
if (options.publicPath) {
|
|
931
|
+
return options.publicPath;
|
|
932
|
+
}
|
|
933
|
+
// Handle empty original base case
|
|
934
|
+
if (originalBase === '') {
|
|
935
|
+
return 'auto';
|
|
936
|
+
}
|
|
937
|
+
// Use viteBase if available, ensuring it ends with a slash
|
|
938
|
+
if (viteBase) {
|
|
939
|
+
return viteBase.replace(/\/?$/, '/');
|
|
940
|
+
}
|
|
941
|
+
// Fallback to auto if no base is specified
|
|
942
|
+
return 'auto';
|
|
943
|
+
}
|
|
944
|
+
|
|
920
945
|
var Manifest = function Manifest() {
|
|
921
946
|
var mfOptions = getNormalizeModuleFederationOptions();
|
|
922
947
|
var name = mfOptions.name,
|
|
@@ -1032,7 +1057,7 @@
|
|
|
1032
1057
|
if (_command === 'serve') {
|
|
1033
1058
|
base = (config.server.origin || '') + config.base;
|
|
1034
1059
|
}
|
|
1035
|
-
publicPath =
|
|
1060
|
+
publicPath = resolvePublicPath(mfOptions, base, _originalConfigBase);
|
|
1036
1061
|
},
|
|
1037
1062
|
/**
|
|
1038
1063
|
* Generates the module federation manifest file
|
|
@@ -1298,7 +1323,8 @@
|
|
|
1298
1323
|
if (_command === 'serve') {
|
|
1299
1324
|
var _viteConfig$server, _viteConfig$server2;
|
|
1300
1325
|
var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
|
|
1301
|
-
|
|
1326
|
+
var publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
|
|
1327
|
+
return Promise.resolve("\n const origin = (window && " + !options.ignoreOrigin + ") ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + " + publicPath + ")\n // __tla only serves as a hack for vite-plugin-top-level-await.\n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
|
|
1302
1328
|
}
|
|
1303
1329
|
return Promise.resolve(code);
|
|
1304
1330
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -36,6 +36,11 @@ export type ModuleFederationOptions = {
|
|
|
36
36
|
remotes?: Record<string, string | RemoteObjectConfig> | undefined;
|
|
37
37
|
runtime?: any;
|
|
38
38
|
shareScope?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Override the public path used for remote entries
|
|
41
|
+
* Defaults to Vite's base config or "auto" if base is empty
|
|
42
|
+
*/
|
|
43
|
+
publicPath?: string;
|
|
39
44
|
shared?: string[] | Record<string, string | {
|
|
40
45
|
name?: string;
|
|
41
46
|
version?: string;
|
|
@@ -70,6 +75,7 @@ export interface NormalizedModuleFederationOptions {
|
|
|
70
75
|
dts?: boolean | PluginDtsOptions;
|
|
71
76
|
shareStrategy: ShareStrategy;
|
|
72
77
|
getPublicPath?: string;
|
|
78
|
+
publicPath?: string;
|
|
73
79
|
ignoreOrigin?: boolean;
|
|
74
80
|
virtualModuleDir: string;
|
|
75
81
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NormalizedModuleFederationOptions } from './normalizeModuleFederationOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the public path for remote entries
|
|
4
|
+
* @param options - Module Federation options
|
|
5
|
+
* @param viteBase - Vite's base config value
|
|
6
|
+
* @param originalBase - Original base config before any transformations
|
|
7
|
+
* @returns The resolved public path
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolvePublicPath(options: NormalizedModuleFederationOptions, viteBase: string, originalBase?: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Vite plugin for Module Federation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,22 +9,6 @@
|
|
|
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
|
-
},
|
|
28
12
|
"repository": {
|
|
29
13
|
"type": "git",
|
|
30
14
|
"url": "git+https://github.com/module-federation/vite.git"
|
|
@@ -44,7 +28,6 @@
|
|
|
44
28
|
"url": "https://github.com/module-federation/vite/issues"
|
|
45
29
|
},
|
|
46
30
|
"homepage": "https://github.com/module-federation/vite#readme",
|
|
47
|
-
"packageManager": "pnpm@9.1.3",
|
|
48
31
|
"dependencies": {
|
|
49
32
|
"@module-federation/runtime": "^0.17.1",
|
|
50
33
|
"@rollup/pluginutils": "^5.1.0",
|
|
@@ -66,5 +49,20 @@
|
|
|
66
49
|
"vite": "^5.4.3",
|
|
67
50
|
"vitest": "^2.1.1",
|
|
68
51
|
"wait-on": "^8.0.1"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"fmt": "prettier --write src",
|
|
55
|
+
"fmt.check": "prettier --check src",
|
|
56
|
+
"format": "pretty-quick",
|
|
57
|
+
"dev": "microbundle watch --no-sourcemap --compress=false",
|
|
58
|
+
"build": "rimraf lib && microbundle --no-sourcemap --compress=false",
|
|
59
|
+
"dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
|
|
60
|
+
"preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
|
|
61
|
+
"dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
|
|
62
|
+
"dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
|
|
63
|
+
"preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
|
|
64
|
+
"multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
|
|
65
|
+
"test": "vitest",
|
|
66
|
+
"e2e": "playwright test"
|
|
69
67
|
}
|
|
70
|
-
}
|
|
68
|
+
}
|