Skip to content

Commit efea502

Browse files
committed
bootstrap检查
1 parent 253e5bf commit efea502

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/virtualModule/initConfig.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ module.exports.getInitConfigModule = function (pluginInstance) {
2727
window["__mfplugin__${options.name}"] = {
2828
wpmjs,
2929
initSharedPromise: null,
30+
initedShared: false,
3031
chunkMap: {},
3132
get(pkg = "") {
33+
if(!this.initedShared) {
34+
throw new Error("'" + pkg.replace("mfshare:", "") + "'" + " cannot be used in entry chunk, please complete the bootstrap(see: https://webpack.js.org/concepts/module-federation/#troubleshooting)")
35+
}
3236
return wpmjs.get(pkgFilter(pkg))
3337
},
3438
import(pkg = "") {
@@ -46,6 +50,9 @@ module.exports.getInitConfigModule = function (pluginInstance) {
4650
const {initShared} = require(${JSON.stringify(virtualSetSharedPath)})
4751
const initConfig = ${JSON.stringify(pluginInstance.wpmInitConfig)}
4852
wpmjs.setConfig(initConfig)
49-
window["__mfplugin__initSharedPromise__${options.name}"] = initShared()
53+
window["__mfplugin__initSharedPromise__${options.name}"] = Promise.resolve(initShared())
54+
.then(function() {
55+
window["__mfplugin__${options.name}"].initedShared = true
56+
})
5057
`
5158
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mf-webpack4",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Webpack 4 Module Federation Plugin",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)