@module-federation/vite 1.0.0-alpha-31ab3f9 → 1.0.0-alpha-0b760f6
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 +48 -26
- package/lib/index.esm.js +48 -26
- package/lib/index.modern.js +28 -9
- package/lib/index.umd.js +48 -26
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -84,12 +84,18 @@ var addEntry = function addEntry(_ref) {
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
buildStart: function buildStart() {
|
|
87
|
-
var _this$emitFile;
|
|
88
87
|
if (_command === "serve") return;
|
|
89
88
|
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes("[hash");
|
|
90
|
-
|
|
91
|
-
name: entryName
|
|
92
|
-
|
|
89
|
+
var emitFileOptions = {
|
|
90
|
+
name: entryName,
|
|
91
|
+
type: 'chunk',
|
|
92
|
+
id: entryPath,
|
|
93
|
+
preserveSignature: 'strict'
|
|
94
|
+
};
|
|
95
|
+
if (!hasHash) {
|
|
96
|
+
emitFileOptions.fileName = fileName;
|
|
97
|
+
}
|
|
98
|
+
this.emitFile(emitFileOptions);
|
|
93
99
|
if (htmlFilePath) {
|
|
94
100
|
var htmlContent = fs__namespace.readFileSync(htmlFilePath, 'utf-8');
|
|
95
101
|
var scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
@@ -628,6 +634,8 @@ var Manifest = function Manifest() {
|
|
|
628
634
|
var extensions;
|
|
629
635
|
var root;
|
|
630
636
|
var remoteEntryFile;
|
|
637
|
+
var publicPath;
|
|
638
|
+
var _command;
|
|
631
639
|
return [{
|
|
632
640
|
name: 'moddule-federation-manifest',
|
|
633
641
|
apply: 'serve',
|
|
@@ -666,7 +674,7 @@ var Manifest = function Manifest() {
|
|
|
666
674
|
},
|
|
667
675
|
globalName: name,
|
|
668
676
|
pluginVersion: '0.2.5',
|
|
669
|
-
publicPath:
|
|
677
|
+
publicPath: publicPath
|
|
670
678
|
},
|
|
671
679
|
shared: Array.from(getUsedShares()).map(function (shareKey) {
|
|
672
680
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
@@ -730,13 +738,20 @@ var Manifest = function Manifest() {
|
|
|
730
738
|
}, {
|
|
731
739
|
name: 'moddule-federation-manifest',
|
|
732
740
|
enforce: 'post',
|
|
733
|
-
config: function config(_config) {
|
|
741
|
+
config: function config(_config, _ref) {
|
|
742
|
+
var command = _ref.command;
|
|
734
743
|
if (!_config.build) _config.build = {};
|
|
735
744
|
if (!_config.build.manifest) _config.build.manifest = _config.build.manifest || !!manifestOptions;
|
|
745
|
+
_command = command;
|
|
736
746
|
},
|
|
737
747
|
configResolved: function configResolved(config) {
|
|
738
748
|
root = config.root;
|
|
739
749
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
750
|
+
publicPath = config.base ? config.base.replace(/\/?$/, "/") : "auto";
|
|
751
|
+
if (_command === "serve") {
|
|
752
|
+
var origin = config.server.origin;
|
|
753
|
+
publicPath = origin ? origin.replace(/\/?$/, "/") : "auto";
|
|
754
|
+
}
|
|
740
755
|
},
|
|
741
756
|
generateBundle: function generateBundle(options, bundle) {
|
|
742
757
|
try {
|
|
@@ -777,7 +792,7 @@ var Manifest = function Manifest() {
|
|
|
777
792
|
var _Object$entries$_i = _Object$entries[_i],
|
|
778
793
|
fileName = _Object$entries$_i[0],
|
|
779
794
|
fileData = _Object$entries$_i[1];
|
|
780
|
-
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name) {
|
|
795
|
+
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name || fileData.name === "remoteEntry") {
|
|
781
796
|
remoteEntryFile = fileData.fileName;
|
|
782
797
|
}
|
|
783
798
|
if (fileData.type === 'chunk') {
|
|
@@ -949,7 +964,7 @@ var Manifest = function Manifest() {
|
|
|
949
964
|
},
|
|
950
965
|
globalName: name,
|
|
951
966
|
pluginVersion: '0.2.5',
|
|
952
|
-
publicPath:
|
|
967
|
+
publicPath: publicPath
|
|
953
968
|
},
|
|
954
969
|
shared: shared,
|
|
955
970
|
remotes: remotes,
|
|
@@ -1097,6 +1112,7 @@ var PromiseStore = /*#__PURE__*/function () {
|
|
|
1097
1112
|
function proxySharedModule(options) {
|
|
1098
1113
|
var _options$shared = options.shared,
|
|
1099
1114
|
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
1115
|
+
var _config;
|
|
1100
1116
|
return [{
|
|
1101
1117
|
name: "generateLocalSharedImportMap",
|
|
1102
1118
|
enforce: "post",
|
|
@@ -1117,16 +1133,20 @@ function proxySharedModule(options) {
|
|
|
1117
1133
|
}, {
|
|
1118
1134
|
name: 'proxyPreBuildShared',
|
|
1119
1135
|
enforce: 'post',
|
|
1120
|
-
|
|
1121
|
-
|
|
1136
|
+
configResolved: function configResolved(config) {
|
|
1137
|
+
_config = config;
|
|
1138
|
+
},
|
|
1139
|
+
config: function config(_config2, _ref) {
|
|
1140
|
+
var _config2$resolve$alia, _config2$resolve$alia2;
|
|
1122
1141
|
var command = _ref.command;
|
|
1123
|
-
(
|
|
1142
|
+
(_config2$resolve$alia = _config2.resolve.alias).push.apply(_config2$resolve$alia, Object.keys(shared).map(function (key) {
|
|
1124
1143
|
var pattern = key.endsWith("/") ? "(^" + key.replace(/\/$/, "") + "(/.+)?$)" : "(^" + key + "$)";
|
|
1125
1144
|
return {
|
|
1126
1145
|
// Intercept all shared requests and proxy them to loadShare
|
|
1127
1146
|
find: new RegExp(pattern),
|
|
1128
1147
|
replacement: "$1",
|
|
1129
1148
|
customResolver: function customResolver(source, importer) {
|
|
1149
|
+
if (/\.css$/.test(source)) return;
|
|
1130
1150
|
var loadSharePath = getLoadShareModulePath(source);
|
|
1131
1151
|
writeLoadShareModule(source, shared[key], command);
|
|
1132
1152
|
writePreBuildLibPath(source);
|
|
@@ -1137,7 +1157,7 @@ function proxySharedModule(options) {
|
|
|
1137
1157
|
};
|
|
1138
1158
|
}));
|
|
1139
1159
|
var savePrebuild = new PromiseStore();
|
|
1140
|
-
(
|
|
1160
|
+
(_config2$resolve$alia2 = _config2.resolve.alias).push.apply(_config2$resolve$alia2, Object.keys(shared).map(function (key) {
|
|
1141
1161
|
return command === "build" ? {
|
|
1142
1162
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1143
1163
|
replacement: function replacement($1) {
|
|
@@ -1151,16 +1171,18 @@ function proxySharedModule(options) {
|
|
|
1151
1171
|
try {
|
|
1152
1172
|
var _this = this;
|
|
1153
1173
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
return Promise.resolve(
|
|
1174
|
+
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1175
|
+
return item.id;
|
|
1176
|
+
})).then(function (result) {
|
|
1177
|
+
if (!result.includes(_config.cacheDir)) {
|
|
1178
|
+
// save pre-bunding module id
|
|
1179
|
+
savePrebuild.set(pkgName, Promise.resolve(result));
|
|
1180
|
+
}
|
|
1181
|
+
// Fix localSharedImportMap import id
|
|
1182
|
+
var _resolve = _this.resolve;
|
|
1183
|
+
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1184
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1185
|
+
});
|
|
1164
1186
|
});
|
|
1165
1187
|
} catch (e) {
|
|
1166
1188
|
return Promise.reject(e);
|
|
@@ -1172,16 +1194,16 @@ function proxySharedModule(options) {
|
|
|
1172
1194
|
}, {
|
|
1173
1195
|
name: "watchLocalSharedImportMap",
|
|
1174
1196
|
apply: "serve",
|
|
1175
|
-
config: function config(
|
|
1176
|
-
|
|
1197
|
+
config: function config(_config3) {
|
|
1198
|
+
_config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
|
|
1177
1199
|
exclude: [getLocalSharedImportMapPath()]
|
|
1178
1200
|
});
|
|
1179
|
-
|
|
1201
|
+
_config3.server = defu.defu(_config3.server, {
|
|
1180
1202
|
watch: {
|
|
1181
1203
|
ignored: []
|
|
1182
1204
|
}
|
|
1183
1205
|
});
|
|
1184
|
-
var watch =
|
|
1206
|
+
var watch = _config3.server.watch;
|
|
1185
1207
|
watch.ignored = [].concat(watch.ignored);
|
|
1186
1208
|
watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
|
|
1187
1209
|
}
|
package/lib/index.esm.js
CHANGED
|
@@ -61,12 +61,18 @@ var addEntry = function addEntry(_ref) {
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
buildStart: function buildStart() {
|
|
64
|
-
var _this$emitFile;
|
|
65
64
|
if (_command === "serve") return;
|
|
66
65
|
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes("[hash");
|
|
67
|
-
|
|
68
|
-
name: entryName
|
|
69
|
-
|
|
66
|
+
var emitFileOptions = {
|
|
67
|
+
name: entryName,
|
|
68
|
+
type: 'chunk',
|
|
69
|
+
id: entryPath,
|
|
70
|
+
preserveSignature: 'strict'
|
|
71
|
+
};
|
|
72
|
+
if (!hasHash) {
|
|
73
|
+
emitFileOptions.fileName = fileName;
|
|
74
|
+
}
|
|
75
|
+
this.emitFile(emitFileOptions);
|
|
70
76
|
if (htmlFilePath) {
|
|
71
77
|
var htmlContent = fs.readFileSync(htmlFilePath, 'utf-8');
|
|
72
78
|
var scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
@@ -605,6 +611,8 @@ var Manifest = function Manifest() {
|
|
|
605
611
|
var extensions;
|
|
606
612
|
var root;
|
|
607
613
|
var remoteEntryFile;
|
|
614
|
+
var publicPath;
|
|
615
|
+
var _command;
|
|
608
616
|
return [{
|
|
609
617
|
name: 'moddule-federation-manifest',
|
|
610
618
|
apply: 'serve',
|
|
@@ -643,7 +651,7 @@ var Manifest = function Manifest() {
|
|
|
643
651
|
},
|
|
644
652
|
globalName: name,
|
|
645
653
|
pluginVersion: '0.2.5',
|
|
646
|
-
publicPath:
|
|
654
|
+
publicPath: publicPath
|
|
647
655
|
},
|
|
648
656
|
shared: Array.from(getUsedShares()).map(function (shareKey) {
|
|
649
657
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
@@ -707,13 +715,20 @@ var Manifest = function Manifest() {
|
|
|
707
715
|
}, {
|
|
708
716
|
name: 'moddule-federation-manifest',
|
|
709
717
|
enforce: 'post',
|
|
710
|
-
config: function config(_config) {
|
|
718
|
+
config: function config(_config, _ref) {
|
|
719
|
+
var command = _ref.command;
|
|
711
720
|
if (!_config.build) _config.build = {};
|
|
712
721
|
if (!_config.build.manifest) _config.build.manifest = _config.build.manifest || !!manifestOptions;
|
|
722
|
+
_command = command;
|
|
713
723
|
},
|
|
714
724
|
configResolved: function configResolved(config) {
|
|
715
725
|
root = config.root;
|
|
716
726
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
727
|
+
publicPath = config.base ? config.base.replace(/\/?$/, "/") : "auto";
|
|
728
|
+
if (_command === "serve") {
|
|
729
|
+
var origin = config.server.origin;
|
|
730
|
+
publicPath = origin ? origin.replace(/\/?$/, "/") : "auto";
|
|
731
|
+
}
|
|
717
732
|
},
|
|
718
733
|
generateBundle: function generateBundle(options, bundle) {
|
|
719
734
|
try {
|
|
@@ -754,7 +769,7 @@ var Manifest = function Manifest() {
|
|
|
754
769
|
var _Object$entries$_i = _Object$entries[_i],
|
|
755
770
|
fileName = _Object$entries$_i[0],
|
|
756
771
|
fileData = _Object$entries$_i[1];
|
|
757
|
-
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name) {
|
|
772
|
+
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name || fileData.name === "remoteEntry") {
|
|
758
773
|
remoteEntryFile = fileData.fileName;
|
|
759
774
|
}
|
|
760
775
|
if (fileData.type === 'chunk') {
|
|
@@ -926,7 +941,7 @@ var Manifest = function Manifest() {
|
|
|
926
941
|
},
|
|
927
942
|
globalName: name,
|
|
928
943
|
pluginVersion: '0.2.5',
|
|
929
|
-
publicPath:
|
|
944
|
+
publicPath: publicPath
|
|
930
945
|
},
|
|
931
946
|
shared: shared,
|
|
932
947
|
remotes: remotes,
|
|
@@ -1074,6 +1089,7 @@ var PromiseStore = /*#__PURE__*/function () {
|
|
|
1074
1089
|
function proxySharedModule(options) {
|
|
1075
1090
|
var _options$shared = options.shared,
|
|
1076
1091
|
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
1092
|
+
var _config;
|
|
1077
1093
|
return [{
|
|
1078
1094
|
name: "generateLocalSharedImportMap",
|
|
1079
1095
|
enforce: "post",
|
|
@@ -1094,16 +1110,20 @@ function proxySharedModule(options) {
|
|
|
1094
1110
|
}, {
|
|
1095
1111
|
name: 'proxyPreBuildShared',
|
|
1096
1112
|
enforce: 'post',
|
|
1097
|
-
|
|
1098
|
-
|
|
1113
|
+
configResolved: function configResolved(config) {
|
|
1114
|
+
_config = config;
|
|
1115
|
+
},
|
|
1116
|
+
config: function config(_config2, _ref) {
|
|
1117
|
+
var _config2$resolve$alia, _config2$resolve$alia2;
|
|
1099
1118
|
var command = _ref.command;
|
|
1100
|
-
(
|
|
1119
|
+
(_config2$resolve$alia = _config2.resolve.alias).push.apply(_config2$resolve$alia, Object.keys(shared).map(function (key) {
|
|
1101
1120
|
var pattern = key.endsWith("/") ? "(^" + key.replace(/\/$/, "") + "(/.+)?$)" : "(^" + key + "$)";
|
|
1102
1121
|
return {
|
|
1103
1122
|
// Intercept all shared requests and proxy them to loadShare
|
|
1104
1123
|
find: new RegExp(pattern),
|
|
1105
1124
|
replacement: "$1",
|
|
1106
1125
|
customResolver: function customResolver(source, importer) {
|
|
1126
|
+
if (/\.css$/.test(source)) return;
|
|
1107
1127
|
var loadSharePath = getLoadShareModulePath(source);
|
|
1108
1128
|
writeLoadShareModule(source, shared[key], command);
|
|
1109
1129
|
writePreBuildLibPath(source);
|
|
@@ -1114,7 +1134,7 @@ function proxySharedModule(options) {
|
|
|
1114
1134
|
};
|
|
1115
1135
|
}));
|
|
1116
1136
|
var savePrebuild = new PromiseStore();
|
|
1117
|
-
(
|
|
1137
|
+
(_config2$resolve$alia2 = _config2.resolve.alias).push.apply(_config2$resolve$alia2, Object.keys(shared).map(function (key) {
|
|
1118
1138
|
return command === "build" ? {
|
|
1119
1139
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1120
1140
|
replacement: function replacement($1) {
|
|
@@ -1128,16 +1148,18 @@ function proxySharedModule(options) {
|
|
|
1128
1148
|
try {
|
|
1129
1149
|
var _this = this;
|
|
1130
1150
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
return Promise.resolve(
|
|
1151
|
+
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1152
|
+
return item.id;
|
|
1153
|
+
})).then(function (result) {
|
|
1154
|
+
if (!result.includes(_config.cacheDir)) {
|
|
1155
|
+
// save pre-bunding module id
|
|
1156
|
+
savePrebuild.set(pkgName, Promise.resolve(result));
|
|
1157
|
+
}
|
|
1158
|
+
// Fix localSharedImportMap import id
|
|
1159
|
+
var _resolve = _this.resolve;
|
|
1160
|
+
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1161
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1162
|
+
});
|
|
1141
1163
|
});
|
|
1142
1164
|
} catch (e) {
|
|
1143
1165
|
return Promise.reject(e);
|
|
@@ -1149,16 +1171,16 @@ function proxySharedModule(options) {
|
|
|
1149
1171
|
}, {
|
|
1150
1172
|
name: "watchLocalSharedImportMap",
|
|
1151
1173
|
apply: "serve",
|
|
1152
|
-
config: function config(
|
|
1153
|
-
|
|
1174
|
+
config: function config(_config3) {
|
|
1175
|
+
_config3.optimizeDeps = defu(_config3.optimizeDeps, {
|
|
1154
1176
|
exclude: [getLocalSharedImportMapPath()]
|
|
1155
1177
|
});
|
|
1156
|
-
|
|
1178
|
+
_config3.server = defu(_config3.server, {
|
|
1157
1179
|
watch: {
|
|
1158
1180
|
ignored: []
|
|
1159
1181
|
}
|
|
1160
1182
|
});
|
|
1161
|
-
var watch =
|
|
1183
|
+
var watch = _config3.server.watch;
|
|
1162
1184
|
watch.ignored = [].concat(watch.ignored);
|
|
1163
1185
|
watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
|
|
1164
1186
|
}
|
package/lib/index.modern.js
CHANGED
|
@@ -67,13 +67,16 @@ const addEntry = ({
|
|
|
67
67
|
buildStart() {
|
|
68
68
|
if (_command === "serve") return;
|
|
69
69
|
const hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes("[hash");
|
|
70
|
-
|
|
70
|
+
const emitFileOptions = {
|
|
71
71
|
name: entryName,
|
|
72
|
-
[hasHash ? "name" : "fileName"]: fileName,
|
|
73
72
|
type: 'chunk',
|
|
74
73
|
id: entryPath,
|
|
75
74
|
preserveSignature: 'strict'
|
|
76
|
-
}
|
|
75
|
+
};
|
|
76
|
+
if (!hasHash) {
|
|
77
|
+
emitFileOptions.fileName = fileName;
|
|
78
|
+
}
|
|
79
|
+
this.emitFile(emitFileOptions);
|
|
77
80
|
if (htmlFilePath) {
|
|
78
81
|
const htmlContent = fs.readFileSync(htmlFilePath, 'utf-8');
|
|
79
82
|
const scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
@@ -694,6 +697,8 @@ const Manifest = () => {
|
|
|
694
697
|
let extensions;
|
|
695
698
|
let root;
|
|
696
699
|
let remoteEntryFile;
|
|
700
|
+
let publicPath;
|
|
701
|
+
let _command;
|
|
697
702
|
return [{
|
|
698
703
|
name: 'moddule-federation-manifest',
|
|
699
704
|
apply: 'serve',
|
|
@@ -732,7 +737,7 @@ const Manifest = () => {
|
|
|
732
737
|
},
|
|
733
738
|
globalName: name,
|
|
734
739
|
pluginVersion: '0.2.5',
|
|
735
|
-
publicPath
|
|
740
|
+
publicPath
|
|
736
741
|
},
|
|
737
742
|
shared: Array.from(getUsedShares()).map(shareKey => {
|
|
738
743
|
const shareItem = getNormalizeShareItem(shareKey);
|
|
@@ -796,13 +801,21 @@ const Manifest = () => {
|
|
|
796
801
|
}, {
|
|
797
802
|
name: 'moddule-federation-manifest',
|
|
798
803
|
enforce: 'post',
|
|
799
|
-
config(config
|
|
804
|
+
config(config, {
|
|
805
|
+
command
|
|
806
|
+
}) {
|
|
800
807
|
if (!config.build) config.build = {};
|
|
801
808
|
if (!config.build.manifest) config.build.manifest = config.build.manifest || !!manifestOptions;
|
|
809
|
+
_command = command;
|
|
802
810
|
},
|
|
803
811
|
configResolved(config) {
|
|
804
812
|
root = config.root;
|
|
805
813
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
814
|
+
publicPath = config.base ? config.base.replace(/\/?$/, "/") : "auto";
|
|
815
|
+
if (_command === "serve") {
|
|
816
|
+
const origin = config.server.origin;
|
|
817
|
+
publicPath = origin ? origin.replace(/\/?$/, "/") : "auto";
|
|
818
|
+
}
|
|
806
819
|
},
|
|
807
820
|
async generateBundle(options, bundle) {
|
|
808
821
|
if (!mfManifestName) return;
|
|
@@ -822,7 +835,7 @@ const Manifest = () => {
|
|
|
822
835
|
};
|
|
823
836
|
// 遍历打包生成的每个文件
|
|
824
837
|
for (const [fileName, fileData] of Object.entries(bundle)) {
|
|
825
|
-
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name) {
|
|
838
|
+
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name || fileData.name === "remoteEntry") {
|
|
826
839
|
remoteEntryFile = fileData.fileName;
|
|
827
840
|
}
|
|
828
841
|
if (fileData.type === 'chunk') {
|
|
@@ -986,7 +999,7 @@ const Manifest = () => {
|
|
|
986
999
|
},
|
|
987
1000
|
globalName: name,
|
|
988
1001
|
pluginVersion: '0.2.5',
|
|
989
|
-
publicPath
|
|
1002
|
+
publicPath
|
|
990
1003
|
},
|
|
991
1004
|
shared,
|
|
992
1005
|
remotes,
|
|
@@ -1128,6 +1141,7 @@ function proxySharedModule(options) {
|
|
|
1128
1141
|
include,
|
|
1129
1142
|
exclude
|
|
1130
1143
|
} = options;
|
|
1144
|
+
let _config;
|
|
1131
1145
|
return [{
|
|
1132
1146
|
name: "generateLocalSharedImportMap",
|
|
1133
1147
|
enforce: "post",
|
|
@@ -1144,6 +1158,9 @@ function proxySharedModule(options) {
|
|
|
1144
1158
|
}, {
|
|
1145
1159
|
name: 'proxyPreBuildShared',
|
|
1146
1160
|
enforce: 'post',
|
|
1161
|
+
configResolved(config) {
|
|
1162
|
+
_config = config;
|
|
1163
|
+
},
|
|
1147
1164
|
config(config, {
|
|
1148
1165
|
command
|
|
1149
1166
|
}) {
|
|
@@ -1154,6 +1171,7 @@ function proxySharedModule(options) {
|
|
|
1154
1171
|
find: new RegExp(pattern),
|
|
1155
1172
|
replacement: "$1",
|
|
1156
1173
|
customResolver(source, importer) {
|
|
1174
|
+
if (/\.css$/.test(source)) return;
|
|
1157
1175
|
const loadSharePath = getLoadShareModulePath(source);
|
|
1158
1176
|
writeLoadShareModule(source, shared[key], command);
|
|
1159
1177
|
writePreBuildLibPath(source);
|
|
@@ -1176,9 +1194,10 @@ function proxySharedModule(options) {
|
|
|
1176
1194
|
replacement: "$1",
|
|
1177
1195
|
async customResolver(source, importer) {
|
|
1178
1196
|
const pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1179
|
-
|
|
1197
|
+
const result = await this.resolve(pkgName).then(item => item.id);
|
|
1198
|
+
if (!result.includes(_config.cacheDir)) {
|
|
1180
1199
|
// save pre-bunding module id
|
|
1181
|
-
savePrebuild.set(pkgName,
|
|
1200
|
+
savePrebuild.set(pkgName, Promise.resolve(result));
|
|
1182
1201
|
}
|
|
1183
1202
|
// Fix localSharedImportMap import id
|
|
1184
1203
|
return await this.resolve(await savePrebuild.get(pkgName));
|
package/lib/index.umd.js
CHANGED
|
@@ -82,12 +82,18 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
buildStart: function buildStart() {
|
|
85
|
-
var _this$emitFile;
|
|
86
85
|
if (_command === "serve") return;
|
|
87
86
|
var hasHash = fileName == null || fileName.includes == null ? void 0 : fileName.includes("[hash");
|
|
88
|
-
|
|
89
|
-
name: entryName
|
|
90
|
-
|
|
87
|
+
var emitFileOptions = {
|
|
88
|
+
name: entryName,
|
|
89
|
+
type: 'chunk',
|
|
90
|
+
id: entryPath,
|
|
91
|
+
preserveSignature: 'strict'
|
|
92
|
+
};
|
|
93
|
+
if (!hasHash) {
|
|
94
|
+
emitFileOptions.fileName = fileName;
|
|
95
|
+
}
|
|
96
|
+
this.emitFile(emitFileOptions);
|
|
91
97
|
if (htmlFilePath) {
|
|
92
98
|
var htmlContent = fs__namespace.readFileSync(htmlFilePath, 'utf-8');
|
|
93
99
|
var scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
@@ -626,6 +632,8 @@
|
|
|
626
632
|
var extensions;
|
|
627
633
|
var root;
|
|
628
634
|
var remoteEntryFile;
|
|
635
|
+
var publicPath;
|
|
636
|
+
var _command;
|
|
629
637
|
return [{
|
|
630
638
|
name: 'moddule-federation-manifest',
|
|
631
639
|
apply: 'serve',
|
|
@@ -664,7 +672,7 @@
|
|
|
664
672
|
},
|
|
665
673
|
globalName: name,
|
|
666
674
|
pluginVersion: '0.2.5',
|
|
667
|
-
publicPath:
|
|
675
|
+
publicPath: publicPath
|
|
668
676
|
},
|
|
669
677
|
shared: Array.from(getUsedShares()).map(function (shareKey) {
|
|
670
678
|
var shareItem = getNormalizeShareItem(shareKey);
|
|
@@ -728,13 +736,20 @@
|
|
|
728
736
|
}, {
|
|
729
737
|
name: 'moddule-federation-manifest',
|
|
730
738
|
enforce: 'post',
|
|
731
|
-
config: function config(_config) {
|
|
739
|
+
config: function config(_config, _ref) {
|
|
740
|
+
var command = _ref.command;
|
|
732
741
|
if (!_config.build) _config.build = {};
|
|
733
742
|
if (!_config.build.manifest) _config.build.manifest = _config.build.manifest || !!manifestOptions;
|
|
743
|
+
_command = command;
|
|
734
744
|
},
|
|
735
745
|
configResolved: function configResolved(config) {
|
|
736
746
|
root = config.root;
|
|
737
747
|
extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
748
|
+
publicPath = config.base ? config.base.replace(/\/?$/, "/") : "auto";
|
|
749
|
+
if (_command === "serve") {
|
|
750
|
+
var origin = config.server.origin;
|
|
751
|
+
publicPath = origin ? origin.replace(/\/?$/, "/") : "auto";
|
|
752
|
+
}
|
|
738
753
|
},
|
|
739
754
|
generateBundle: function generateBundle(options, bundle) {
|
|
740
755
|
try {
|
|
@@ -775,7 +790,7 @@
|
|
|
775
790
|
var _Object$entries$_i = _Object$entries[_i],
|
|
776
791
|
fileName = _Object$entries$_i[0],
|
|
777
792
|
fileData = _Object$entries$_i[1];
|
|
778
|
-
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name) {
|
|
793
|
+
if (mfOptions.filename.replace(/[\[\]]/g, "_") === fileData.name || fileData.name === "remoteEntry") {
|
|
779
794
|
remoteEntryFile = fileData.fileName;
|
|
780
795
|
}
|
|
781
796
|
if (fileData.type === 'chunk') {
|
|
@@ -947,7 +962,7 @@
|
|
|
947
962
|
},
|
|
948
963
|
globalName: name,
|
|
949
964
|
pluginVersion: '0.2.5',
|
|
950
|
-
publicPath:
|
|
965
|
+
publicPath: publicPath
|
|
951
966
|
},
|
|
952
967
|
shared: shared,
|
|
953
968
|
remotes: remotes,
|
|
@@ -1095,6 +1110,7 @@
|
|
|
1095
1110
|
function proxySharedModule(options) {
|
|
1096
1111
|
var _options$shared = options.shared,
|
|
1097
1112
|
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
1113
|
+
var _config;
|
|
1098
1114
|
return [{
|
|
1099
1115
|
name: "generateLocalSharedImportMap",
|
|
1100
1116
|
enforce: "post",
|
|
@@ -1115,16 +1131,20 @@
|
|
|
1115
1131
|
}, {
|
|
1116
1132
|
name: 'proxyPreBuildShared',
|
|
1117
1133
|
enforce: 'post',
|
|
1118
|
-
|
|
1119
|
-
|
|
1134
|
+
configResolved: function configResolved(config) {
|
|
1135
|
+
_config = config;
|
|
1136
|
+
},
|
|
1137
|
+
config: function config(_config2, _ref) {
|
|
1138
|
+
var _config2$resolve$alia, _config2$resolve$alia2;
|
|
1120
1139
|
var command = _ref.command;
|
|
1121
|
-
(
|
|
1140
|
+
(_config2$resolve$alia = _config2.resolve.alias).push.apply(_config2$resolve$alia, Object.keys(shared).map(function (key) {
|
|
1122
1141
|
var pattern = key.endsWith("/") ? "(^" + key.replace(/\/$/, "") + "(/.+)?$)" : "(^" + key + "$)";
|
|
1123
1142
|
return {
|
|
1124
1143
|
// Intercept all shared requests and proxy them to loadShare
|
|
1125
1144
|
find: new RegExp(pattern),
|
|
1126
1145
|
replacement: "$1",
|
|
1127
1146
|
customResolver: function customResolver(source, importer) {
|
|
1147
|
+
if (/\.css$/.test(source)) return;
|
|
1128
1148
|
var loadSharePath = getLoadShareModulePath(source);
|
|
1129
1149
|
writeLoadShareModule(source, shared[key], command);
|
|
1130
1150
|
writePreBuildLibPath(source);
|
|
@@ -1135,7 +1155,7 @@
|
|
|
1135
1155
|
};
|
|
1136
1156
|
}));
|
|
1137
1157
|
var savePrebuild = new PromiseStore();
|
|
1138
|
-
(
|
|
1158
|
+
(_config2$resolve$alia2 = _config2.resolve.alias).push.apply(_config2$resolve$alia2, Object.keys(shared).map(function (key) {
|
|
1139
1159
|
return command === "build" ? {
|
|
1140
1160
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1141
1161
|
replacement: function replacement($1) {
|
|
@@ -1149,16 +1169,18 @@
|
|
|
1149
1169
|
try {
|
|
1150
1170
|
var _this = this;
|
|
1151
1171
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
return Promise.resolve(
|
|
1172
|
+
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1173
|
+
return item.id;
|
|
1174
|
+
})).then(function (result) {
|
|
1175
|
+
if (!result.includes(_config.cacheDir)) {
|
|
1176
|
+
// save pre-bunding module id
|
|
1177
|
+
savePrebuild.set(pkgName, Promise.resolve(result));
|
|
1178
|
+
}
|
|
1179
|
+
// Fix localSharedImportMap import id
|
|
1180
|
+
var _resolve = _this.resolve;
|
|
1181
|
+
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1182
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1183
|
+
});
|
|
1162
1184
|
});
|
|
1163
1185
|
} catch (e) {
|
|
1164
1186
|
return Promise.reject(e);
|
|
@@ -1170,16 +1192,16 @@
|
|
|
1170
1192
|
}, {
|
|
1171
1193
|
name: "watchLocalSharedImportMap",
|
|
1172
1194
|
apply: "serve",
|
|
1173
|
-
config: function config(
|
|
1174
|
-
|
|
1195
|
+
config: function config(_config3) {
|
|
1196
|
+
_config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
|
|
1175
1197
|
exclude: [getLocalSharedImportMapPath()]
|
|
1176
1198
|
});
|
|
1177
|
-
|
|
1199
|
+
_config3.server = defu.defu(_config3.server, {
|
|
1178
1200
|
watch: {
|
|
1179
1201
|
ignored: []
|
|
1180
1202
|
}
|
|
1181
1203
|
});
|
|
1182
|
-
var watch =
|
|
1204
|
+
var watch = _config3.server.watch;
|
|
1183
1205
|
watch.ignored = [].concat(watch.ignored);
|
|
1184
1206
|
watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
|
|
1185
1207
|
}
|