@@ -6,7 +6,10 @@ const os = require('os');
66const transformErrors = require ( './core/transformErrors' ) ;
77const formatErrors = require ( './core/formatErrors' ) ;
88const output = require ( './output' ) ;
9- const concat = require ( './utils' ) . concat ;
9+ const utils = require ( './utils' ) ;
10+
11+ const concat = utils . concat ;
12+ const uniqueBy = utils . uniqueBy ;
1013
1114const defaultTransformers = [
1215 require ( './transformers/babelSyntax' ) ,
@@ -44,12 +47,12 @@ class FriendlyErrorsWebpackPlugin {
4447 }
4548
4649 if ( hasErrors ) {
47- this . displayErrors ( stats . compilation . errors , 'error' ) ;
50+ this . displayErrors ( extractErrorsFromStats ( stats , ' errors' ) , 'error' ) ;
4851 return ;
4952 }
5053
5154 if ( hasWarnings ) {
52- this . displayErrors ( stats . compilation . warnings , 'warning' ) ;
55+ this . displayErrors ( extractErrorsFromStats ( stats , ' warnings' ) , 'warning' ) ;
5356 }
5457 } ) ;
5558
@@ -66,7 +69,7 @@ class FriendlyErrorsWebpackPlugin {
6669 }
6770
6871 displaySuccess ( stats ) {
69- const time = stats . endTime - stats . startTime ;
72+ const time = getCompileTime ( stats ) ;
7073 output . title ( 'success' , 'DONE' , 'Compiled successfully in ' + time + 'ms' ) ;
7174
7275 if ( this . compilationSuccessInfo . messages ) {
@@ -98,6 +101,31 @@ class FriendlyErrorsWebpackPlugin {
98101 }
99102}
100103
104+ function extractErrorsFromStats ( stats , type ) {
105+ if ( isMultiStats ( stats ) ) {
106+ const errors = stats . stats
107+ . reduce ( ( errors , stats ) => errors . concat ( extractErrorsFromStats ( stats , type ) ) , [ ] ) ;
108+ // Dedupe to avoid showing the same error many times when multiple
109+ // compilers depend on the same module.
110+ return uniqueBy ( errors , error => error . message ) ;
111+ }
112+ return stats . compilation [ type ] ;
113+ }
114+
115+ function getCompileTime ( stats ) {
116+ if ( isMultiStats ( stats ) ) {
117+ // Webpack multi compilations run in parallel so using the longest duration.
118+ // https://webpack.github.io/docs/configuration.html#multiple-configurations
119+ return stats . stats
120+ . reduce ( ( time , stats ) => Math . max ( time , getCompileTime ( stats ) ) , 0 ) ;
121+ }
122+ return stats . endTime - stats . startTime ;
123+ }
124+
125+ function isMultiStats ( stats ) {
126+ return stats . stats ;
127+ }
128+
101129function getMaxSeverityErrors ( errors ) {
102130 const maxSeverity = getMaxInt ( errors , 'severity' ) ;
103131 return errors . filter ( e => e . severity === maxSeverity ) ;
0 commit comments