Skip to content

Commit

Permalink
Support plugin API of webpack v3 and v4
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed Feb 28, 2018
1 parent dfd30d6 commit e052aed
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions middleware.js
Expand Up @@ -12,16 +12,23 @@ function webpackHotMiddleware(compiler, opts) {
var eventStream = createEventStream(opts.heartbeat);
var latestStats = null;

compiler.plugin("compile", function() {
if (compiler.hooks) {
compiler.hooks.compile.tap("webpack-hot-middleware", onCompile);
compiler.hooks.done.tap("webpack-hot-middleware", onDone);
} else {
compiler.plugin("compile", onCompile);
compiler.plugin("done", onDone);
}
function onCompile() {
latestStats = null;
if (opts.log) opts.log("webpack building...");
eventStream.publish({action: "building"});
});
compiler.plugin("done", function(statsResult) {
}
function onDone(statsResult) {
// Keep hold of latest stats so they can be propagated to new clients
latestStats = statsResult;
publishStats("built", latestStats, eventStream, opts.log);
});
}
var middleware = function(req, res, next) {
if (!pathMatch(req.url, opts.path)) return next();
eventStream.handler(req, res);
Expand Down

0 comments on commit e052aed

Please sign in to comment.