@module-federation/vite 1.7.1 → 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 +290 -141
- package/lib/index.esm.js +291 -142
- package/lib/index.modern.js +263 -130
- package/lib/index.umd.js +290 -141
- package/lib/plugins/pluginMFManifest.d.ts +1 -1
- package/lib/utils/__tests__/cssModuleHelpers.test.d.ts +1 -0
- package/lib/utils/__tests__/helpers.d.ts +2 -0
- package/lib/utils/__tests__/publicPath.test.d.ts +1 -0
- package/lib/utils/cssModuleHelpers.d.ts +75 -0
- package/lib/utils/normalizeModuleFederationOptions.d.ts +6 -0
- package/lib/utils/publicPath.d.ts +9 -0
- package/package.json +2 -1
package/lib/index.umd.js
CHANGED
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
emitFileOptions.fileName = fileName;
|
|
121
121
|
}
|
|
122
122
|
emitFileId = this.emitFile(emitFileOptions);
|
|
123
|
-
if (htmlFilePath) {
|
|
123
|
+
if (htmlFilePath && fs__namespace.existsSync(htmlFilePath)) {
|
|
124
124
|
var htmlContent = fs__namespace.readFileSync(htmlFilePath, 'utf-8');
|
|
125
125
|
var scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
126
126
|
var match;
|
|
@@ -159,10 +159,14 @@
|
|
|
159
159
|
*/
|
|
160
160
|
function PluginDevProxyModuleTopLevelAwait() {
|
|
161
161
|
var filterFunction = pluginutils.createFilter();
|
|
162
|
+
var processedFlag = '/* already-processed-by-dev-proxy-module-top-level-await */';
|
|
162
163
|
return {
|
|
163
164
|
name: 'dev-proxy-module-top-level-await',
|
|
164
165
|
apply: 'serve',
|
|
165
166
|
transform: function transform(code, id) {
|
|
167
|
+
if (code.includes(processedFlag)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
166
170
|
if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
|
|
167
171
|
return null;
|
|
168
172
|
}
|
|
@@ -215,8 +219,9 @@
|
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
});
|
|
222
|
+
var transformedCode = magicString.toString();
|
|
218
223
|
return {
|
|
219
|
-
code:
|
|
224
|
+
code: processedFlag + "\n" + transformedCode,
|
|
220
225
|
map: magicString.generateMap({
|
|
221
226
|
hires: true
|
|
222
227
|
})
|
|
@@ -458,6 +463,7 @@
|
|
|
458
463
|
dev: options.dev,
|
|
459
464
|
dts: options.dts,
|
|
460
465
|
getPublicPath: options.getPublicPath,
|
|
466
|
+
publicPath: options.publicPath,
|
|
461
467
|
shareStrategy: options.shareStrategy || 'version-first',
|
|
462
468
|
ignoreOrigin: options.ignoreOrigin || false,
|
|
463
469
|
virtualModuleDir: options.virtualModuleDir || '__mf__virtual'
|
|
@@ -714,9 +720,9 @@
|
|
|
714
720
|
}
|
|
715
721
|
function generateLocalSharedImportMap() {
|
|
716
722
|
var options = getNormalizeModuleFederationOptions();
|
|
717
|
-
return "\n const importMap = {\n " + Array.from(getUsedShares()).map(function (pkg) {
|
|
723
|
+
return "\n const importMap = {\n " + Array.from(getUsedShares()).sort().map(function (pkg) {
|
|
718
724
|
return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
|
|
719
|
-
}).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
|
|
725
|
+
}).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).sort().map(function (key) {
|
|
720
726
|
var shareItem = getNormalizeShareItem(key);
|
|
721
727
|
if (!shareItem) return null;
|
|
722
728
|
return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(key) + ",\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 usedShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = importMap \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 ";
|
|
@@ -764,6 +770,178 @@
|
|
|
764
770
|
writeRuntimeInitStatus();
|
|
765
771
|
}
|
|
766
772
|
|
|
773
|
+
var ASSET_TYPES = ['js', 'css'];
|
|
774
|
+
var LOAD_TIMINGS = ['sync', 'async'];
|
|
775
|
+
var JS_EXTENSIONS = ['.ts', '.tsx', '.jsx', '.mjs', '.cjs'];
|
|
776
|
+
/**
|
|
777
|
+
* Creates an empty asset map structure for tracking JS and CSS assets
|
|
778
|
+
* @returns Initialized asset map with sync/async arrays for JS and CSS
|
|
779
|
+
*/
|
|
780
|
+
var createEmptyAssetMap = function createEmptyAssetMap() {
|
|
781
|
+
return {
|
|
782
|
+
js: {
|
|
783
|
+
sync: [],
|
|
784
|
+
async: []
|
|
785
|
+
},
|
|
786
|
+
css: {
|
|
787
|
+
sync: [],
|
|
788
|
+
async: []
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* Tracks an asset in the preload map with deduplication
|
|
794
|
+
* @param map - The preload map to update
|
|
795
|
+
* @param key - The module key to track under
|
|
796
|
+
* @param fileName - The asset filename to track
|
|
797
|
+
* @param isAsync - Whether the asset is loaded async
|
|
798
|
+
* @param type - The asset type ('js' or 'css')
|
|
799
|
+
*/
|
|
800
|
+
var trackAsset = function trackAsset(map, key, fileName, isAsync, type) {
|
|
801
|
+
if (!map[key]) {
|
|
802
|
+
map[key] = createEmptyAssetMap();
|
|
803
|
+
}
|
|
804
|
+
var target = isAsync ? map[key][type].async : map[key][type].sync;
|
|
805
|
+
if (!target.includes(fileName)) {
|
|
806
|
+
target.push(fileName);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Checks if a file is a CSS file by extension
|
|
811
|
+
* @param fileName - The filename to check
|
|
812
|
+
* @returns True if file has a CSS extension (.css, .scss, .less)
|
|
813
|
+
*/
|
|
814
|
+
var isCSSFile = function isCSSFile(fileName) {
|
|
815
|
+
return fileName.endsWith('.css') || fileName.endsWith('.scss') || fileName.endsWith('.less');
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* Collects all CSS assets from the bundle
|
|
819
|
+
* @param bundle - The Rollup output bundle
|
|
820
|
+
* @returns Set of CSS asset filenames
|
|
821
|
+
*/
|
|
822
|
+
var collectCssAssets = function collectCssAssets(bundle) {
|
|
823
|
+
var cssAssets = new Set();
|
|
824
|
+
for (var _i = 0, _Object$entries = Object.entries(bundle); _i < _Object$entries.length; _i++) {
|
|
825
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
826
|
+
fileName = _Object$entries$_i[0],
|
|
827
|
+
fileData = _Object$entries$_i[1];
|
|
828
|
+
if (fileData.type === 'asset' && isCSSFile(fileName)) {
|
|
829
|
+
cssAssets.add(fileName);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return cssAssets;
|
|
833
|
+
};
|
|
834
|
+
/**
|
|
835
|
+
* Processes module assets and tracks them in the files map
|
|
836
|
+
* @param bundle - The Rollup output bundle
|
|
837
|
+
* @param filesMap - The preload map to populate
|
|
838
|
+
* @param moduleMatcher - Function that matches module paths to keys
|
|
839
|
+
*/
|
|
840
|
+
var processModuleAssets = function processModuleAssets(bundle, filesMap, moduleMatcher) {
|
|
841
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(bundle); _i2 < _Object$entries2.length; _i2++) {
|
|
842
|
+
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
843
|
+
fileName = _Object$entries2$_i[0],
|
|
844
|
+
fileData = _Object$entries2$_i[1];
|
|
845
|
+
if (fileData.type !== 'chunk') continue;
|
|
846
|
+
if (!fileData.modules) continue;
|
|
847
|
+
for (var _i3 = 0, _Object$keys = Object.keys(fileData.modules); _i3 < _Object$keys.length; _i3++) {
|
|
848
|
+
var modulePath = _Object$keys[_i3];
|
|
849
|
+
var matchKey = moduleMatcher(modulePath);
|
|
850
|
+
if (!matchKey) continue;
|
|
851
|
+
// Track main JS chunk
|
|
852
|
+
trackAsset(filesMap, matchKey, fileName, false, 'js');
|
|
853
|
+
// Handle dynamic imports
|
|
854
|
+
if (fileData.dynamicImports) {
|
|
855
|
+
for (var _iterator = _createForOfIteratorHelperLoose(fileData.dynamicImports), _step; !(_step = _iterator()).done;) {
|
|
856
|
+
var dynamicImport = _step.value;
|
|
857
|
+
var importData = bundle[dynamicImport];
|
|
858
|
+
if (!importData) continue;
|
|
859
|
+
var isCss = isCSSFile(dynamicImport);
|
|
860
|
+
trackAsset(filesMap, matchKey, dynamicImport, true, isCss ? 'css' : 'js');
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* Deduplicates assets in the files map
|
|
868
|
+
* @param filesMap - The preload map to deduplicate
|
|
869
|
+
* @returns New deduplicated preload map
|
|
870
|
+
*/
|
|
871
|
+
var deduplicateAssets = function deduplicateAssets(filesMap) {
|
|
872
|
+
var result = {};
|
|
873
|
+
for (var _i4 = 0, _Object$entries3 = Object.entries(filesMap); _i4 < _Object$entries3.length; _i4++) {
|
|
874
|
+
var _Object$entries3$_i = _Object$entries3[_i4],
|
|
875
|
+
key = _Object$entries3$_i[0],
|
|
876
|
+
assetMaps = _Object$entries3$_i[1];
|
|
877
|
+
result[key] = createEmptyAssetMap();
|
|
878
|
+
for (var _i5 = 0, _ASSET_TYPES = ASSET_TYPES; _i5 < _ASSET_TYPES.length; _i5++) {
|
|
879
|
+
var type = _ASSET_TYPES[_i5];
|
|
880
|
+
for (var _i6 = 0, _LOAD_TIMINGS = LOAD_TIMINGS; _i6 < _LOAD_TIMINGS.length; _i6++) {
|
|
881
|
+
var timing = _LOAD_TIMINGS[_i6];
|
|
882
|
+
result[key][type][timing] = Array.from(new Set(assetMaps[type][timing]));
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return result;
|
|
887
|
+
};
|
|
888
|
+
/**
|
|
889
|
+
* Builds a mapping between module files and their share keys
|
|
890
|
+
* @param shareKeys - Set of share keys to map
|
|
891
|
+
* @param resolveFn - Function to resolve module paths
|
|
892
|
+
* @returns Map of file paths to their corresponding share keys
|
|
893
|
+
*/
|
|
894
|
+
var buildFileToShareKeyMap = function buildFileToShareKeyMap(shareKeys, resolveFn) {
|
|
895
|
+
try {
|
|
896
|
+
var fileToShareKey = new Map();
|
|
897
|
+
return Promise.resolve(Promise.all(Array.from(shareKeys).map(function (shareKey) {
|
|
898
|
+
return resolveFn(getPreBuildLibImportId(shareKey)).then(function (resolution) {
|
|
899
|
+
var _resolution$id;
|
|
900
|
+
return {
|
|
901
|
+
shareKey: shareKey,
|
|
902
|
+
file: resolution == null || (_resolution$id = resolution.id) == null ? void 0 : _resolution$id.split('?')[0]
|
|
903
|
+
};
|
|
904
|
+
})["catch"](function () {
|
|
905
|
+
return null;
|
|
906
|
+
});
|
|
907
|
+
}))).then(function (resolutions) {
|
|
908
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(resolutions), _step2; !(_step2 = _iterator2()).done;) {
|
|
909
|
+
var resolution = _step2.value;
|
|
910
|
+
if (resolution != null && resolution.file) {
|
|
911
|
+
fileToShareKey.set(resolution.file, resolution.shareKey);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return fileToShareKey;
|
|
915
|
+
});
|
|
916
|
+
} catch (e) {
|
|
917
|
+
return Promise.reject(e);
|
|
918
|
+
}
|
|
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
|
+
|
|
767
945
|
var Manifest = function Manifest() {
|
|
768
946
|
var mfOptions = getNormalizeModuleFederationOptions();
|
|
769
947
|
var name = mfOptions.name,
|
|
@@ -775,21 +953,43 @@
|
|
|
775
953
|
mfManifestName = 'mf-manifest.json';
|
|
776
954
|
}
|
|
777
955
|
if (typeof manifestOptions !== 'boolean') {
|
|
778
|
-
mfManifestName =
|
|
956
|
+
mfManifestName = path__namespace.join((manifestOptions == null ? void 0 : manifestOptions.filePath) || '', (manifestOptions == null ? void 0 : manifestOptions.fileName) || '');
|
|
779
957
|
}
|
|
780
|
-
var extensions;
|
|
781
958
|
var root;
|
|
782
959
|
var remoteEntryFile;
|
|
783
960
|
var publicPath;
|
|
784
961
|
var _command;
|
|
785
962
|
var _originalConfigBase;
|
|
786
963
|
var viteConfig;
|
|
964
|
+
/**
|
|
965
|
+
* Adds global CSS assets to all module exports
|
|
966
|
+
* @param filesMap - The preload map to update
|
|
967
|
+
* @param cssAssets - Set of CSS asset filenames to add
|
|
968
|
+
*/
|
|
969
|
+
var addCssAssetsToAllExports = function addCssAssetsToAllExports(filesMap, cssAssets) {
|
|
970
|
+
Object.keys(filesMap).forEach(function (key) {
|
|
971
|
+
cssAssets.forEach(function (cssAsset) {
|
|
972
|
+
trackAsset(filesMap, key, cssAsset, false, 'css');
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
};
|
|
787
976
|
return [{
|
|
788
977
|
name: 'module-federation-manifest',
|
|
789
978
|
apply: 'serve',
|
|
979
|
+
/**
|
|
980
|
+
* Stores resolved Vite config for later use
|
|
981
|
+
*/
|
|
982
|
+
/**
|
|
983
|
+
* Finalizes configuration after all plugins are resolved
|
|
984
|
+
* @param config - Fully resolved Vite config
|
|
985
|
+
*/
|
|
790
986
|
configResolved: function configResolved(config) {
|
|
791
987
|
viteConfig = config;
|
|
792
988
|
},
|
|
989
|
+
/**
|
|
990
|
+
* Configures dev server middleware to handle manifest requests
|
|
991
|
+
* @param server - Vite dev server instance
|
|
992
|
+
*/
|
|
793
993
|
configureServer: function configureServer(server) {
|
|
794
994
|
server.middlewares.use(function (req, res, next) {
|
|
795
995
|
var _req$url;
|
|
@@ -837,137 +1037,85 @@
|
|
|
837
1037
|
}, {
|
|
838
1038
|
name: 'module-federation-manifest',
|
|
839
1039
|
enforce: 'post',
|
|
1040
|
+
/**
|
|
1041
|
+
* Initial plugin configuration
|
|
1042
|
+
* @param config - Vite config object
|
|
1043
|
+
* @param command - Current Vite command (serve/build)
|
|
1044
|
+
*/
|
|
840
1045
|
config: function config(_config, _ref) {
|
|
841
1046
|
var command = _ref.command;
|
|
842
1047
|
if (!_config.build) _config.build = {};
|
|
843
|
-
if (!_config.build.manifest)
|
|
1048
|
+
if (!_config.build.manifest) {
|
|
1049
|
+
_config.build.manifest = _config.build.manifest || !!manifestOptions;
|
|
1050
|
+
}
|
|
844
1051
|
_command = command;
|
|
845
1052
|
_originalConfigBase = _config.base;
|
|
846
1053
|
},
|
|
847
1054
|
configResolved: function configResolved(config) {
|
|
848
1055
|
root = config.root;
|
|
849
|
-
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
850
1056
|
var base = config.base;
|
|
851
1057
|
if (_command === 'serve') {
|
|
852
1058
|
base = (config.server.origin || '') + config.base;
|
|
853
1059
|
}
|
|
854
|
-
publicPath =
|
|
1060
|
+
publicPath = resolvePublicPath(mfOptions, base, _originalConfigBase);
|
|
855
1061
|
},
|
|
1062
|
+
/**
|
|
1063
|
+
* Generates the module federation manifest file
|
|
1064
|
+
* @param options - Rollup output options
|
|
1065
|
+
* @param bundle - Generated bundle assets
|
|
1066
|
+
*/
|
|
856
1067
|
generateBundle: function generateBundle(options, bundle) {
|
|
857
1068
|
try {
|
|
858
1069
|
var _this = this;
|
|
859
|
-
// 递归查找模块的同步导入文件
|
|
860
|
-
var _findSynchronousImports = function findSynchronousImports(fileName, array) {
|
|
861
|
-
var fileData = bundle[fileName];
|
|
862
|
-
if (fileData && fileData.type === 'chunk') {
|
|
863
|
-
array.push(fileName); // 将当前文件加入预加载列表
|
|
864
|
-
// 遍历该文件的同步导入文件
|
|
865
|
-
fileData.imports.forEach(function (importedFile) {
|
|
866
|
-
if (array.indexOf(importedFile) === -1) {
|
|
867
|
-
_findSynchronousImports(importedFile, array); // 递归查找同步导入的文件
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
1070
|
if (!mfManifestName) return Promise.resolve();
|
|
873
|
-
var
|
|
874
|
-
|
|
875
|
-
}); // 获取你提供的 moduleIds
|
|
876
|
-
var filesContainingModules = {};
|
|
877
|
-
// 帮助函数:检查模块路径是否匹配
|
|
878
|
-
var isModuleMatched = function isModuleMatched(relativeModulePath, preloadModule) {
|
|
879
|
-
// 先尝试直接匹配
|
|
880
|
-
if (relativeModulePath === preloadModule) return true;
|
|
881
|
-
// 如果 preloadModule 没有后缀,尝试添加可能的后缀进行匹配
|
|
882
|
-
for (var _iterator = _createForOfIteratorHelperLoose(extensions), _step; !(_step = _iterator()).done;) {
|
|
883
|
-
var ext = _step.value;
|
|
884
|
-
if (relativeModulePath === "" + preloadModule + ext) {
|
|
885
|
-
return true;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
return false;
|
|
889
|
-
};
|
|
890
|
-
// 遍历打包生成的每个文件
|
|
1071
|
+
var filesMap = {};
|
|
1072
|
+
// First pass: Find remoteEntry file
|
|
891
1073
|
for (var _i = 0, _Object$entries = Object.entries(bundle); _i < _Object$entries.length; _i++) {
|
|
892
1074
|
var _Object$entries$_i = _Object$entries[_i],
|
|
893
|
-
|
|
1075
|
+
_ = _Object$entries$_i[0],
|
|
894
1076
|
fileData = _Object$entries$_i[1];
|
|
895
1077
|
if (mfOptions.filename.replace(/[\[\]]/g, '_').replace(/\.[^/.]+$/, '') === fileData.name || fileData.name === 'remoteEntry') {
|
|
896
1078
|
remoteEntryFile = fileData.fileName;
|
|
897
|
-
|
|
898
|
-
if (fileData.type === 'chunk') {
|
|
899
|
-
// 遍历该文件的所有模块
|
|
900
|
-
for (var _i2 = 0, _Object$keys = Object.keys(fileData.modules); _i2 < _Object$keys.length; _i2++) {
|
|
901
|
-
var modulePath = _Object$keys[_i2];
|
|
902
|
-
// 将绝对路径转换为相对于 Vite root 的相对路径
|
|
903
|
-
var relativeModulePath = path.relative(root, modulePath);
|
|
904
|
-
// 检查模块是否在 preloadModules 列表中
|
|
905
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(exposesModules), _step2; !(_step2 = _iterator2()).done;) {
|
|
906
|
-
var preloadModule = _step2.value;
|
|
907
|
-
var formatPreloadModule = preloadModule.replace('./', '');
|
|
908
|
-
if (isModuleMatched(relativeModulePath, formatPreloadModule)) {
|
|
909
|
-
var _filesContainingModul;
|
|
910
|
-
if (!filesContainingModules[preloadModule]) {
|
|
911
|
-
filesContainingModules[preloadModule] = {
|
|
912
|
-
sync: [],
|
|
913
|
-
async: []
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
console.log(Object.keys(fileData.modules));
|
|
917
|
-
filesContainingModules[preloadModule].sync.push(fileName);
|
|
918
|
-
(_filesContainingModul = filesContainingModules[preloadModule].async).push.apply(_filesContainingModul, fileData.dynamicImports || []);
|
|
919
|
-
_findSynchronousImports(fileName, filesContainingModules[preloadModule].sync);
|
|
920
|
-
break; // 如果找到匹配,跳出循环
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
1079
|
+
break; // We can break early since we only need to find remoteEntry once
|
|
924
1080
|
}
|
|
925
1081
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
var _Object$entries2$_i = _Object$entries2[_i3],
|
|
940
|
-
_fileName = _Object$entries2$_i[0],
|
|
941
|
-
_fileData = _Object$entries2$_i[1];
|
|
942
|
-
if (_fileData.type === 'chunk') {
|
|
943
|
-
// 遍历该文件的所有模块
|
|
944
|
-
for (var _i4 = 0, _Object$keys2 = Object.keys(_fileData.modules); _i4 < _Object$keys2.length; _i4++) {
|
|
945
|
-
var _modulePath = _Object$keys2[_i4];
|
|
946
|
-
var sharedKey = fileToShareKey[_modulePath];
|
|
947
|
-
if (sharedKey) {
|
|
948
|
-
var _filesContainingModul2;
|
|
949
|
-
if (!filesContainingModules[sharedKey]) {
|
|
950
|
-
filesContainingModules[sharedKey] = {
|
|
951
|
-
sync: [],
|
|
952
|
-
async: []
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
filesContainingModules[sharedKey].sync.push(_fileName);
|
|
956
|
-
(_filesContainingModul2 = filesContainingModules[sharedKey].async).push.apply(_filesContainingModul2, _fileData.dynamicImports || []);
|
|
957
|
-
_findSynchronousImports(_fileName, filesContainingModules[sharedKey].sync);
|
|
958
|
-
break; // 如果找到匹配,跳出循环
|
|
959
|
-
}
|
|
960
|
-
}
|
|
1082
|
+
// Second pass: Collect all CSS assets
|
|
1083
|
+
var allCssAssets = collectCssAssets(bundle);
|
|
1084
|
+
var exposesModules = Object.keys(mfOptions.exposes).map(function (item) {
|
|
1085
|
+
return mfOptions.exposes[item]["import"];
|
|
1086
|
+
});
|
|
1087
|
+
// Process exposed modules
|
|
1088
|
+
processModuleAssets(bundle, filesMap, function (modulePath) {
|
|
1089
|
+
var absoluteModulePath = path__namespace.resolve(root, modulePath);
|
|
1090
|
+
return exposesModules.find(function (exposeModule) {
|
|
1091
|
+
var exposePath = path__namespace.resolve(root, exposeModule);
|
|
1092
|
+
// First try exact path match
|
|
1093
|
+
if (absoluteModulePath === exposePath) {
|
|
1094
|
+
return true;
|
|
961
1095
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1096
|
+
// Then try path match without known extensions
|
|
1097
|
+
var getPathWithoutKnownExt = function getPathWithoutKnownExt(filePath) {
|
|
1098
|
+
var ext = path__namespace.extname(filePath);
|
|
1099
|
+
return JS_EXTENSIONS.includes(ext) ? path__namespace.join(path__namespace.dirname(filePath), path__namespace.basename(filePath, ext)) : filePath;
|
|
1100
|
+
};
|
|
1101
|
+
var modulePathNoExt = getPathWithoutKnownExt(absoluteModulePath);
|
|
1102
|
+
var exposePathNoExt = getPathWithoutKnownExt(exposePath);
|
|
1103
|
+
return modulePathNoExt === exposePathNoExt;
|
|
1104
|
+
});
|
|
1105
|
+
});
|
|
1106
|
+
// Process shared modules
|
|
1107
|
+
return Promise.resolve(buildFileToShareKeyMap(getUsedShares(), _this.resolve.bind(_this))).then(function (fileToShareKey) {
|
|
1108
|
+
processModuleAssets(bundle, filesMap, function (modulePath) {
|
|
1109
|
+
return fileToShareKey.get(modulePath);
|
|
966
1110
|
});
|
|
1111
|
+
// Add all CSS assets to every export
|
|
1112
|
+
addCssAssetsToAllExports(filesMap, allCssAssets);
|
|
1113
|
+
// Final deduplication of all assets
|
|
1114
|
+
filesMap = deduplicateAssets(filesMap);
|
|
967
1115
|
_this.emitFile({
|
|
968
1116
|
type: 'asset',
|
|
969
1117
|
fileName: mfManifestName,
|
|
970
|
-
source: JSON.stringify(generateMFManifest(
|
|
1118
|
+
source: JSON.stringify(generateMFManifest(filesMap))
|
|
971
1119
|
});
|
|
972
1120
|
});
|
|
973
1121
|
} catch (e) {
|
|
@@ -975,6 +1123,11 @@
|
|
|
975
1123
|
}
|
|
976
1124
|
}
|
|
977
1125
|
}];
|
|
1126
|
+
/**
|
|
1127
|
+
* Generates the final manifest JSON structure
|
|
1128
|
+
* @param preloadMap - Map of module assets to include
|
|
1129
|
+
* @returns Complete manifest object
|
|
1130
|
+
*/
|
|
978
1131
|
function generateMFManifest(preloadMap) {
|
|
979
1132
|
var options = getNormalizeModuleFederationOptions();
|
|
980
1133
|
var name = options.name;
|
|
@@ -983,23 +1136,23 @@
|
|
|
983
1136
|
path: '',
|
|
984
1137
|
type: 'module'
|
|
985
1138
|
};
|
|
986
|
-
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1139
|
+
// Process remotes
|
|
1140
|
+
var remotes = Array.from(Object.entries(getUsedRemotesMap())).flatMap(function (_ref2) {
|
|
1141
|
+
var remoteKey = _ref2[0],
|
|
1142
|
+
modules = _ref2[1];
|
|
1143
|
+
return Array.from(modules).map(function (moduleKey) {
|
|
1144
|
+
return {
|
|
992
1145
|
federationContainerName: options.remotes[remoteKey].entry,
|
|
993
1146
|
moduleName: moduleKey.replace(remoteKey, '').replace('/', ''),
|
|
994
1147
|
alias: remoteKey,
|
|
995
1148
|
entry: '*'
|
|
996
|
-
}
|
|
1149
|
+
};
|
|
997
1150
|
});
|
|
998
1151
|
});
|
|
999
|
-
//
|
|
1152
|
+
// Process shared dependencies
|
|
1000
1153
|
var shared = Array.from(getUsedShares()).map(function (shareKey) {
|
|
1001
|
-
var _preloadMap$shareKey, _preloadMap$shareKey2;
|
|
1002
1154
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
1155
|
+
var assets = preloadMap[shareKey] || createEmptyAssetMap();
|
|
1003
1156
|
return {
|
|
1004
1157
|
id: name + ":" + shareKey,
|
|
1005
1158
|
name: shareKey,
|
|
@@ -1007,42 +1160,40 @@
|
|
|
1007
1160
|
requiredVersion: shareItem.shareConfig.requiredVersion,
|
|
1008
1161
|
assets: {
|
|
1009
1162
|
js: {
|
|
1010
|
-
async:
|
|
1011
|
-
sync:
|
|
1163
|
+
async: assets.js.async,
|
|
1164
|
+
sync: assets.js.sync
|
|
1012
1165
|
},
|
|
1013
1166
|
css: {
|
|
1014
|
-
async:
|
|
1015
|
-
sync:
|
|
1167
|
+
async: assets.css.async,
|
|
1168
|
+
sync: assets.css.sync
|
|
1016
1169
|
}
|
|
1017
1170
|
}
|
|
1018
1171
|
};
|
|
1019
|
-
}).filter(
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
// assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
|
|
1172
|
+
}).filter(Boolean);
|
|
1173
|
+
// Process exposed modules
|
|
1174
|
+
var exposes = Object.entries(options.exposes).map(function (_ref3) {
|
|
1175
|
+
var key = _ref3[0],
|
|
1176
|
+
value = _ref3[1];
|
|
1025
1177
|
var formatKey = key.replace('./', '');
|
|
1026
|
-
var sourceFile =
|
|
1178
|
+
var sourceFile = value["import"];
|
|
1179
|
+
var assets = preloadMap[sourceFile] || createEmptyAssetMap();
|
|
1027
1180
|
return {
|
|
1028
|
-
id: name +
|
|
1181
|
+
id: name + ":" + formatKey,
|
|
1029
1182
|
name: formatKey,
|
|
1030
1183
|
assets: {
|
|
1031
1184
|
js: {
|
|
1032
|
-
async:
|
|
1033
|
-
sync:
|
|
1185
|
+
async: assets.js.async,
|
|
1186
|
+
sync: assets.js.sync
|
|
1034
1187
|
},
|
|
1035
1188
|
css: {
|
|
1036
|
-
|
|
1037
|
-
|
|
1189
|
+
async: assets.css.async,
|
|
1190
|
+
sync: assets.css.sync
|
|
1038
1191
|
}
|
|
1039
1192
|
},
|
|
1040
1193
|
path: key
|
|
1041
1194
|
};
|
|
1042
|
-
}).filter(
|
|
1043
|
-
|
|
1044
|
-
}); // Filter out any null values
|
|
1045
|
-
var result = {
|
|
1195
|
+
}).filter(Boolean);
|
|
1196
|
+
return {
|
|
1046
1197
|
id: name,
|
|
1047
1198
|
name: name,
|
|
1048
1199
|
metaData: _extends({
|
|
@@ -1057,8 +1208,6 @@
|
|
|
1057
1208
|
types: {
|
|
1058
1209
|
path: '',
|
|
1059
1210
|
name: ''
|
|
1060
|
-
// "zip": "@mf-types.zip",
|
|
1061
|
-
// "api": "@mf-types.d.ts"
|
|
1062
1211
|
},
|
|
1063
1212
|
globalName: name,
|
|
1064
1213
|
pluginVersion: '0.2.5'
|
|
@@ -1071,7 +1220,6 @@
|
|
|
1071
1220
|
remotes: remotes,
|
|
1072
1221
|
exposes: exposes
|
|
1073
1222
|
};
|
|
1074
|
-
return result;
|
|
1075
1223
|
}
|
|
1076
1224
|
};
|
|
1077
1225
|
|
|
@@ -1175,7 +1323,8 @@
|
|
|
1175
1323
|
if (_command === 'serve') {
|
|
1176
1324
|
var _viteConfig$server, _viteConfig$server2;
|
|
1177
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';
|
|
1178
|
-
|
|
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 ");
|
|
1179
1328
|
}
|
|
1180
1329
|
return Promise.resolve(code);
|
|
1181
1330
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|