diff --git a/middleware.js b/middleware.js index 0cb1b2f25..b2fb47b9e 100644 --- a/middleware.js +++ b/middleware.js @@ -8,6 +8,28 @@ var parseRange = require("range-parser"); var HASH_REGEXP = /[0-9a-f]{10,}/; +var defaultReporter = function (reporterOptions) { + var state = reporterOptions.state; + var stats = reporterOptions.stats; + var options = reporterOptions.options; + + if(state) { + var displayStats = (!options.quiet && options.stats !== false); + if(displayStats && + !(stats.hasErrors() || stats.hasWarnings()) && + options.noInfo) + displayStats = false; + if(displayStats) { + console.log(stats.toString(options.stats)) + } + if(!options.noInfo && !options.quiet) { + console.info("webpack: bundle is now VALID."); + } + } else { + console.info("webpack: bundle is now INVALID."); + } +} + // constructor for the middleware module.exports = function(compiler, options) { if(!options) options = {}; @@ -28,6 +50,7 @@ module.exports = function(compiler, options) { options.filename = new RegExp("^[\/]{0,1}" + str + "$"); } } + if(typeof options.reporter !== "function") options.reporter = defaultReporter; // store our files in memory var files = {}; @@ -42,16 +65,7 @@ module.exports = function(compiler, options) { // check if still in valid state if(!state) return; // print webpack output - var displayStats = (!options.quiet && options.stats !== false); - if(displayStats && - !(stats.hasErrors() || stats.hasWarnings()) && - options.noInfo) - displayStats = false; - if(displayStats) { - console.log(stats.toString(options.stats)); - } - if (!options.noInfo && !options.quiet) - console.info("webpack: bundle is now VALID."); + options.reporter({ state: true, stats: stats, options: options }); // execute callback that are delayed var cbs = callbacks; @@ -71,7 +85,7 @@ module.exports = function(compiler, options) { // on compiling function invalidPlugin() { if(state && (!options.noInfo && !options.quiet)) - console.info("webpack: bundle is now INVALID."); + options.reporter({ state: false, options: options }) // We are now in invalid state state = false; }