@@ -8,6 +8,28 @@ var parseRange = require("range-parser");
8
8
9
9
var HASH_REGEXP = / [ 0 - 9 a - f ] { 10 , } / ;
10
10
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
+
11
33
// constructor for the middleware
12
34
module . exports = function ( compiler , options ) {
13
35
if ( ! options ) options = { } ;
@@ -28,6 +50,7 @@ module.exports = function(compiler, options) {
28
50
options . filename = new RegExp ( "^[\/]{0,1}" + str + "$" ) ;
29
51
}
30
52
}
53
+ if ( typeof options . reporter !== "function" ) options . reporter = defaultReporter ;
31
54
32
55
// store our files in memory
33
56
var files = { } ;
@@ -42,16 +65,7 @@ module.exports = function(compiler, options) {
42
65
// check if still in valid state
43
66
if ( ! state ) return ;
44
67
// 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 } ) ;
55
69
56
70
// execute callback that are delayed
57
71
var cbs = callbacks ;
@@ -71,7 +85,7 @@ module.exports = function(compiler, options) {
71
85
// on compiling
72
86
function invalidPlugin ( ) {
73
87
if ( state && ( ! options . noInfo && ! options . quiet ) )
74
- console . info ( "webpack: bundle is now INVALID." ) ;
88
+ options . reporter ( { state : false , options : options } )
75
89
// We are now in invalid state
76
90
state = false ;
77
91
}
0 commit comments