Skip to content

Commit f941380

Browse files
NitiveSpaceK33z
authored andcommitted
Reporter option (#91)
* Add reporter option * Move defaultReporter to separate function
1 parent 356477a commit f941380

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

middleware.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ var parseRange = require("range-parser");
88

99
var HASH_REGEXP = /[0-9a-f]{10,}/;
1010

11+
var defaultReporter = function (reporterOptions) {
12+
var state = reporterOptions.state;
13+
var stats = reporterOptions.stats;
14+
var options = reporterOptions.options;
15+
16+
if(state) {
17+
var displayStats = (!options.quiet && options.stats !== false);
18+
if(displayStats &&
19+
!(stats.hasErrors() || stats.hasWarnings()) &&
20+
options.noInfo)
21+
displayStats = false;
22+
if(displayStats) {
23+
console.log(stats.toString(options.stats))
24+
}
25+
if(!options.noInfo && !options.quiet) {
26+
console.info("webpack: bundle is now VALID.");
27+
}
28+
} else {
29+
console.info("webpack: bundle is now INVALID.");
30+
}
31+
}
32+
1133
// constructor for the middleware
1234
module.exports = function(compiler, options) {
1335
if(!options) options = {};
@@ -28,6 +50,7 @@ module.exports = function(compiler, options) {
2850
options.filename = new RegExp("^[\/]{0,1}" + str + "$");
2951
}
3052
}
53+
if(typeof options.reporter !== "function") options.reporter = defaultReporter;
3154

3255
// store our files in memory
3356
var files = {};
@@ -42,16 +65,7 @@ module.exports = function(compiler, options) {
4265
// check if still in valid state
4366
if(!state) return;
4467
// print webpack output
45-
var displayStats = (!options.quiet && options.stats !== false);
46-
if(displayStats &&
47-
!(stats.hasErrors() || stats.hasWarnings()) &&
48-
options.noInfo)
49-
displayStats = false;
50-
if(displayStats) {
51-
console.log(stats.toString(options.stats));
52-
}
53-
if (!options.noInfo && !options.quiet)
54-
console.info("webpack: bundle is now VALID.");
68+
options.reporter({ state: true, stats: stats, options: options });
5569

5670
// execute callback that are delayed
5771
var cbs = callbacks;
@@ -71,7 +85,7 @@ module.exports = function(compiler, options) {
7185
// on compiling
7286
function invalidPlugin() {
7387
if(state && (!options.noInfo && !options.quiet))
74-
console.info("webpack: bundle is now INVALID.");
88+
options.reporter({ state: false, options: options })
7589
// We are now in invalid state
7690
state = false;
7791
}

0 commit comments

Comments
 (0)