mirror of https://github.com/webpack/webpack.git
parent
4891225efc
commit
636d97e180
|
|
@ -152,7 +152,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|||
return this.asString([
|
||||
source + ",",
|
||||
"hot: hotCreateModule(" + varModuleId + "),",
|
||||
"parents: [hotCurrentParent],",
|
||||
"parents: hotCurrentParents,",
|
||||
"children: []"
|
||||
]);
|
||||
});
|
||||
|
|
@ -211,20 +211,30 @@ var hotInitCode = Template.getFunctionContent(function() {
|
|||
var hotApplyOnUpdate = true;
|
||||
var hotCurrentHash = $hash$;
|
||||
var hotCurrentModuleData = {};
|
||||
var hotCurrentParent = 0;
|
||||
var hotCurrentParents = [];
|
||||
|
||||
function hotCreateRequire(moduleId) {
|
||||
var me = installedModules[moduleId];
|
||||
if(!me) return $require$;
|
||||
var fn = function(request) {
|
||||
if(installedModules[request] && installedModules[request].parents.indexOf(moduleId) < 0)
|
||||
installedModules[request].parents.push(moduleId);
|
||||
if(me && me.children.indexOf(request) < 0)
|
||||
me.children.push(request);
|
||||
hotCurrentParent = moduleId;
|
||||
if(me.hot.active) {
|
||||
if(installedModules[request]) {
|
||||
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
||||
installedModules[request].parents.push(moduleId);
|
||||
if(me.children.indexOf(request) < 0)
|
||||
me.children.push(request);
|
||||
} else hotCurrentParents = [moduleId];
|
||||
} else {
|
||||
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
||||
hotCurrentParents = [];
|
||||
}
|
||||
return $require$(request);
|
||||
};
|
||||
for(var name in $require$)
|
||||
fn[name] = $require$[name];
|
||||
for(var name in $require$) {
|
||||
if(Object.prototype.hasOwnProperty.call($require$, name)) {
|
||||
fn[name] = $require$[name];
|
||||
}
|
||||
}
|
||||
fn.e = function(chunkId, callback) {
|
||||
if(hotStatus === "ready")
|
||||
hotSetStatus("prepare");
|
||||
|
|
@ -261,6 +271,7 @@ var hotInitCode = Template.getFunctionContent(function() {
|
|||
_disposeHandlers: [],
|
||||
|
||||
// Module API
|
||||
active: true,
|
||||
accept: function(dep, callback) {
|
||||
if(typeof dep === "undefined")
|
||||
hot._selfAccepted = true;
|
||||
|
|
@ -528,6 +539,9 @@ var hotInitCode = Template.getFunctionContent(function() {
|
|||
}
|
||||
hotCurrentModuleData[moduleId] = data;
|
||||
|
||||
// disable module (this disables requires from this module)
|
||||
module.hot.active = false;
|
||||
|
||||
// remove module from cache
|
||||
delete installedModules[moduleId];
|
||||
|
||||
|
|
@ -600,7 +614,7 @@ var hotInitCode = Template.getFunctionContent(function() {
|
|||
for(var i = 0; i < outdatedSelfAcceptedModules.length; i++) {
|
||||
var item = outdatedSelfAcceptedModules[i];
|
||||
var moduleId = item.module;
|
||||
hotCurrentParent = moduleId;
|
||||
hotCurrentParents = [moduleId];
|
||||
try {
|
||||
$require$(moduleId);
|
||||
} catch(err) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue