Skip to content

Reporter option #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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 = {};
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down