webpack-hot-middleware
Advanced tools
Comparing version 2.23.1 to 2.24.0
@@ -14,2 +14,3 @@ module.exports = webpackHotMiddleware; | ||
var latestStats = null; | ||
var closed = false; | ||
@@ -24,2 +25,3 @@ if (compiler.hooks) { | ||
function onInvalid() { | ||
if (closed) return; | ||
latestStats = null; | ||
@@ -30,2 +32,3 @@ if (opts.log) opts.log("webpack building..."); | ||
function onDone(statsResult) { | ||
if (closed) return; | ||
// Keep hold of latest stats so they can be propagated to new clients | ||
@@ -36,2 +39,3 @@ latestStats = statsResult; | ||
var middleware = function(req, res, next) { | ||
if (closed) return next(); | ||
if (!pathMatch(req.url, opts.path)) return next(); | ||
@@ -45,3 +49,14 @@ eventStream.handler(req, res); | ||
}; | ||
middleware.publish = eventStream.publish; | ||
middleware.publish = function(payload) { | ||
if (closed) return; | ||
eventStream.publish(payload); | ||
}; | ||
middleware.close = function() { | ||
if (closed) return; | ||
// Can't remove compiler plugins, so we just set a flag and noop if closed | ||
// https://github.com/webpack/tapable/issues/32#issuecomment-350644466 | ||
closed = true; | ||
eventStream.close(); | ||
eventStream = null; | ||
}; | ||
return middleware; | ||
@@ -58,3 +73,3 @@ } | ||
} | ||
setInterval(function heartbeatTick() { | ||
var interval = setInterval(function heartbeatTick() { | ||
everyClient(function(client) { | ||
@@ -65,2 +80,9 @@ client.write("data: \uD83D\uDC93\n\n"); | ||
return { | ||
close: function() { | ||
clearInterval(interval); | ||
everyClient(function(client) { | ||
if (!client.finished) client.end(); | ||
}); | ||
clients = {}; | ||
}, | ||
handler: function(req, res) { | ||
@@ -89,2 +111,3 @@ var headers = { | ||
req.on("close", function(){ | ||
if (!res.finished) res.end(); | ||
delete clients[id]; | ||
@@ -91,0 +114,0 @@ }); |
{ | ||
"name": "webpack-hot-middleware", | ||
"version": "2.23.1", | ||
"version": "2.24.0", | ||
"description": "Webpack hot reloading you can attach to your own server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30938
641