mirror of https://github.com/webpack/webpack.git
Merge pull request #4617 from ricmatsui/rm-fix-hot-module-replacement
Fix hot module main flag for hot module replacement
This commit is contained in:
commit
c1ce93a1a9
|
|
@ -8,7 +8,7 @@ module.exports = function() {
|
||||||
var hotApplyOnUpdate = true;
|
var hotApplyOnUpdate = true;
|
||||||
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
||||||
var hotCurrentModuleData = {};
|
var hotCurrentModuleData = {};
|
||||||
var hotMainModule = true; // eslint-disable-line no-unused-vars
|
var hotCurrentChildModule; // eslint-disable-line no-unused-vars
|
||||||
var hotCurrentParents = []; // eslint-disable-line no-unused-vars
|
var hotCurrentParents = []; // eslint-disable-line no-unused-vars
|
||||||
var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
|
var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
|
|
@ -20,14 +20,16 @@ module.exports = function() {
|
||||||
if(installedModules[request]) {
|
if(installedModules[request]) {
|
||||||
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
||||||
installedModules[request].parents.push(moduleId);
|
installedModules[request].parents.push(moduleId);
|
||||||
} else hotCurrentParents = [moduleId];
|
} else {
|
||||||
|
hotCurrentParents = [moduleId];
|
||||||
|
hotCurrentChildModule = request;
|
||||||
|
}
|
||||||
if(me.children.indexOf(request) < 0)
|
if(me.children.indexOf(request) < 0)
|
||||||
me.children.push(request);
|
me.children.push(request);
|
||||||
} else {
|
} else {
|
||||||
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
||||||
hotCurrentParents = [];
|
hotCurrentParents = [];
|
||||||
}
|
}
|
||||||
hotMainModule = false;
|
|
||||||
return $require$(request);
|
return $require$(request);
|
||||||
};
|
};
|
||||||
var ObjectFactory = function ObjectFactory(name) {
|
var ObjectFactory = function ObjectFactory(name) {
|
||||||
|
|
@ -82,7 +84,7 @@ module.exports = function() {
|
||||||
_selfAccepted: false,
|
_selfAccepted: false,
|
||||||
_selfDeclined: false,
|
_selfDeclined: false,
|
||||||
_disposeHandlers: [],
|
_disposeHandlers: [],
|
||||||
_main: hotMainModule,
|
_main: hotCurrentChildModule !== moduleId,
|
||||||
|
|
||||||
// Module API
|
// Module API
|
||||||
active: true,
|
active: true,
|
||||||
|
|
@ -135,7 +137,7 @@ module.exports = function() {
|
||||||
//inherit from previous dispose call
|
//inherit from previous dispose call
|
||||||
data: hotCurrentModuleData[moduleId]
|
data: hotCurrentModuleData[moduleId]
|
||||||
};
|
};
|
||||||
hotMainModule = true;
|
hotCurrentChildModule = undefined;
|
||||||
return hot;
|
return hot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = "common";
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
require("should");
|
||||||
|
|
||||||
|
require("./common");
|
||||||
|
|
||||||
|
it("should have the correct main flag for multi first module", function() {
|
||||||
|
var multiModule = __webpack_require__.c[module.parents[0]];
|
||||||
|
multiModule.hot._main.should.be.eql(true);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
require("should");
|
||||||
|
|
||||||
|
require("./common");
|
||||||
|
|
||||||
|
it("should have the correct main flag for multi second module", function() {
|
||||||
|
var multiModule = __webpack_require__.c[module.parents[0]];
|
||||||
|
multiModule.hot._main.should.be.eql(true);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = "shared";
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
module.exports = {
|
||||||
|
findBundle: function(i, options) {
|
||||||
|
return [
|
||||||
|
"./vendor.js",
|
||||||
|
"./first.js",
|
||||||
|
"./second.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
require("./common");
|
||||||
|
|
||||||
|
module.exports = "vendor";
|
||||||
|
|
||||||
|
it("should have the correct main flag for multi vendor module", function() {
|
||||||
|
var multiModule = __webpack_require__.c[module.parents[0]];
|
||||||
|
multiModule.hot._main.should.be.eql(true);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
var CommonsChunkPlugin = require("../../../../lib/optimize/CommonsChunkPlugin");
|
||||||
|
var HotModuleReplacementPlugin = require("../../../../lib/HotModuleReplacementPlugin");
|
||||||
|
module.exports = {
|
||||||
|
entry: {
|
||||||
|
vendor: ["./vendor"],
|
||||||
|
first: ["./shared", "./first"],
|
||||||
|
second: ["./shared", "./second"]
|
||||||
|
},
|
||||||
|
target: "web",
|
||||||
|
output: {
|
||||||
|
filename: "[name].js"
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new CommonsChunkPlugin({
|
||||||
|
name: "vendor"
|
||||||
|
}),
|
||||||
|
new HotModuleReplacementPlugin()
|
||||||
|
]
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue