Skip to content

Commit 74cdfb7

Browse files
committed
more fixes webpack#26
1 parent 2e5fc25 commit 74cdfb7

5 files changed

Lines changed: 41 additions & 16 deletions

File tree

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
6767
if(currentChunk) {
6868
currentChunk.modules.forEach(function(module) {
6969
var idx = removedModules.indexOf(module.id);
70-
if(idx >= 0)
70+
if(idx >= 0) {
7171
removedModules.splice(idx, 1);
72-
if(!module.hotUpdate) return;
72+
if(!module.hotUpdate) return;
73+
}
7374
newModules.push(module);
7475
});
7576
}
@@ -126,6 +127,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
126127
buf.push(buf.pop() + ",");
127128
buf.push("hot: hotCreateModule(" + varModuleId + "),");
128129
buf.push("parents: [hotCurrentParent],");
130+
buf.push("data: hotCurrentModuleData[" + varModuleId + "],");
129131
buf.push("children: []");
130132
return buf;
131133
};
@@ -224,6 +226,7 @@ var hotInitCode = function() {
224226

225227
var hotApplyOnUpdate = true;
226228
var hotCurrentHash = $hash$;
229+
var hotCurrentModuleData = {};
227230
var hotCurrentParent = 0;
228231

229232
function hotCreateRequire(moduleId) {
@@ -240,14 +243,22 @@ var hotInitCode = function() {
240243
if(hotStatus === "ready") throw new Error("Cannot load chunks when update is ready");
241244
hotChunksLoading++;
242245
$require$.e(chunkId, function() {
243-
callback(fn);
244-
hotChunksLoading--;
245-
if(hotStatus === "prepare") {
246-
if(!hotWaitingFilesMap[chunkId]) {
247-
hotDownloadUpdateChunk(chunkId);
248-
}
249-
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
250-
hotUpdateDownloaded();
246+
try {
247+
callback(fn);
248+
} catch(e) {
249+
finishChunkLoading();
250+
throw e;
251+
}
252+
finishChunkLoading();
253+
function finishChunkLoading() {
254+
hotChunksLoading--;
255+
if(hotStatus === "prepare") {
256+
if(!hotWaitingFilesMap[chunkId]) {
257+
hotDownloadUpdateChunk(chunkId);
258+
}
259+
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
260+
hotUpdateDownloaded();
261+
}
251262
}
252263
}
253264
});
@@ -380,15 +391,15 @@ var hotInitCode = function() {
380391
});
381392

382393
hotSetStatus("dispose");
383-
var oldModulesData = {};
394+
hotCurrentModuleData = {};
384395
outdatedModules.forEach(function(moduleId) {
385396
var data = {};
386397
var module = installedModules[moduleId];
387398
if(!module) return;
388399
module.hot._disposeHandlers.forEach(function(cb) {
389400
cb(data);
390401
});
391-
oldModulesData[moduleId] = data;
402+
hotCurrentModuleData[moduleId] = data;
392403
}, this);
393404
outdatedModules.forEach(function(moduleId) {
394405
var module = installedModules[moduleId];

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.11.0-beta1",
3+
"version": "0.11.0-beta2",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {

‎test/browsertest/lib/index.web.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe("main", function() {
6969
});
7070

7171
it("should cache modules correctly", function(done) {
72+
delete require.cache[require.resolve("./singluar.js")];
7273
require("./singluar.js").value.should.be.eql(1);
7374
(require("./singluar.js")).value.should.be.eql(1);
7475
require("./sing" + "luar.js").value = 2;
@@ -561,3 +562,15 @@ describe("main", function() {
561562
});
562563

563564
});
565+
566+
if(module.hot) {
567+
module.hot.accept();
568+
module.hot.dispose(function() {
569+
mocha.suite.suites.length = 0;
570+
var stats = document.getElementById("stats");
571+
stats.parentNode.removeChild(stats);
572+
});
573+
if(module.data) {
574+
mocha.run();
575+
}
576+
}

‎test/browsertest/middlewareTest.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var app = express();
88
app.configure(function() {
99
app.use(webpackMiddleware(webpack({
1010
context: __dirname,
11-
entry: "./lib/index",
11+
entry: ["../../hot/poll?10000", "./lib/index"],
1212
debug: true,
1313
devtool: "sourcemap",
1414
module: {
@@ -26,8 +26,10 @@ app.configure(function() {
2626
}
2727
},
2828
optimize: {
29-
minimize: true
29+
minimize: true,
30+
dedupe: true
3031
},
32+
hot: true,
3133
recordsPath: path.join(__dirname, "webpack.records.json"),
3234
output: {
3335
publicPath: "http://localhost:8080/js/",

‎test/browsertest/tests.html‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<link rel="stylesheet" href="mocha.css" />
66
</head>
77
<body>
8-
<div id="mocha"></div>
98
<script src="mocha.js"></script>
109
<script src="chai.js"></script>
1110
<script>

0 commit comments

Comments
 (0)