Skip to content

Commit fb93f62

Browse files
committed
Fix hot module main flag for hot module replacement
When a main module is loaded after a module which is already installed, the main module should still be marked as a main module.
1 parent 06b6cbb commit fb93f62

8 files changed

Lines changed: 50 additions & 1 deletion

File tree

lib/HotModuleReplacement.runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function() {
2727
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
2828
hotCurrentParents = [];
2929
}
30-
hotMainModule = false;
30+
hotMainModule = !!installedModules[request];
3131
return $require$(request);
3232
};
3333
var ObjectFactory = function ObjectFactory(name) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "common";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require("should");
2+
3+
require("./common");
4+
5+
it("should have the correct main flag for multi first module", function() {
6+
var multiModule = __webpack_require__.c[module.parents[0]];
7+
multiModule.hot._main.should.be.eql(true);
8+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require("should");
2+
3+
require("./common");
4+
5+
it("should have the correct main flag for multi second module", function() {
6+
var multiModule = __webpack_require__.c[module.parents[0]];
7+
multiModule.hot._main.should.be.eql(true);
8+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "shared";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
findBundle: function(i, options) {
3+
return [
4+
"./vendor.js",
5+
"./first.js",
6+
"./second.js"
7+
]
8+
}
9+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require("./common");
2+
3+
module.exports = "vendor";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var CommonsChunkPlugin = require("../../../../lib/optimize/CommonsChunkPlugin");
2+
var HotModuleReplacementPlugin = require("../../../../lib/HotModuleReplacementPlugin");
3+
module.exports = {
4+
entry: {
5+
vendor: ["./vendor"],
6+
first: ["./shared", "./first"],
7+
second: ["./shared", "./second"]
8+
},
9+
target: "web",
10+
output: {
11+
filename: "[name].js"
12+
},
13+
plugins: [
14+
new CommonsChunkPlugin({
15+
name: "vendor"
16+
}),
17+
new HotModuleReplacementPlugin()
18+
]
19+
};

0 commit comments

Comments
 (0)