From 309f25287b83b32d42759f1eaa76230283ac7517 Mon Sep 17 00:00:00 2001 From: Merott Movahedi Date: Fri, 29 Jan 2016 17:23:52 +0000 Subject: [PATCH] feat(onUpdate): accept a callback as options.onUpdate If options.onUpdate is provided, it will be called with the stats results of the compilation on every build. In combination with setting options.quiet, it allows the user to manually handle the logging of the stats. --- README.md | 4 ++++ middleware.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index c1442a970..c8d64508c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ app.use(webpackMiddleware(webpack({ // switch into lazy mode // that means no watching, but recompilation on every request + onUpdate: function(stats) { doWhateverWithStats(stats); }, + // manually handle the stats from the last compilation + // can be combined with quiet and noInfo for full control over output + watchOptions: { aggregateTimeout: 300, poll: true diff --git a/middleware.js b/middleware.js index 5b52cf163..bb1527926 100644 --- a/middleware.js +++ b/middleware.js @@ -40,6 +40,10 @@ module.exports = function(compiler, options) { process.nextTick(function() { // check if still in valid state if(!state) return; + + // make a callback with stats + if(typeof options.onUpdate === 'function') options.onUpdate(stats); + // print webpack output var displayStats = (!options.quiet && options.stats !== false); if(displayStats &&