@@ -3,12 +3,72 @@ const fs = require('fs');
33const chalk = require ( 'chalk' ) ;
44const Table = require ( 'cli-table3' ) ;
55
6+
7+ function setUpHookForCompiler ( compiler , outputOptions , options ) {
8+ compiler . hooks . beforeRun . tap ( 'webpackProgress' , compilation => {
9+ if ( outputOptions . progress ) {
10+ let tmp_msg ;
11+ const defaultProgressPluginHandler = ( percent , msg , addInfo ) => {
12+ percent = Math . floor ( percent * 100 ) ;
13+ if ( percent === 100 ) {
14+ msg = 'Compilation completed' ;
15+ }
16+
17+ if ( msg && tmp_msg != msg ) {
18+ process . cliLogger . info ( percent + '% ' + msg ) ;
19+ }
20+ tmp_msg = msg ;
21+ } ;
22+ if ( ! progressPluginExists ) {
23+ new ProgressPlugin ( defaultProgressPluginHandler ) . apply ( compiler ) ;
24+ } else {
25+ if ( ! progressPluginExists . handler ) {
26+ options . plugins = options . plugins . filter ( e => e !== progressPluginExists ) ;
27+ Object . keys ( progressPluginExists ) . map ( opt => {
28+ ProgressPlugin . defaultOptions [ opt ] = progressPluginExists [ opt ] ;
29+ } ) ;
30+ new ProgressPlugin ( defaultProgressPluginHandler ) . apply ( compiler ) ;
31+ } else {
32+ progressPluginExists . apply ( compiler ) ;
33+ }
34+ }
35+ }
36+ } ) ;
37+
38+ if ( outputOptions . infoVerbosity === 'verbose' ) {
39+ if ( outputOptions . watch ) {
40+ compiler . hooks . watchRun . tap ( 'WebpackInfo' , compilation => {
41+ const compilationName = compilation . name ? compilation . name : '' ;
42+ process . cliLogger . info ( 'Compilation ' + compilationName + ' starting…' ) ;
43+ } ) ;
44+ } else {
45+ compiler . hooks . beforeRun . tap ( 'WebpackInfo' , compilation => {
46+ const compilationName = compilation . name ? compilation . name : '' ;
47+ process . cliLogger . info ( 'Compilation ' + compilationName + ' starting…' ) ;
48+ } ) ;
49+ }
50+ compiler . hooks . done . tap ( 'WebpackInfo' , compilation => {
51+ const compilationName = compilation . name ? compilation . name : '' ;
52+ process . cliLogger . info ( 'Compilation ' + compilationName + ' finished' ) ;
53+ } ) ;
54+ }
55+ }
56+
657function showEmojiConditionally ( ) {
758 return ( process . stdout . isTTY && process . platform === 'darwin' )
859}
960
1061function generateOutput ( outputOptions , stats , statsErrors ) {
1162 const statsObj = stats . toJson ( outputOptions ) ;
63+ if ( statsObj . children && statsObj . children . length ) {
64+ statsObj . children . forEach ( child => {
65+ generateOutputForSingleCompilation ( child , statsErrors ) ;
66+ } ) ;
67+ return ;
68+ }
69+ generateOutputForSingleCompilation ( statsObj , statsErrors ) ;
70+ }
71+ function generateOutputForSingleCompilation ( statsObj , statsErrors ) {
1272 const { assets, entrypoints, time, builtAt, warnings, outputPath } = statsObj ;
1373
1474 const visibleEmojies = showEmojiConditionally ( ) ? [ '✅' , '🌏' , '⚒️ ' , '⏱ ' , '📂' ] : new Array ( 5 ) . fill ( '' ) ;
@@ -140,54 +200,14 @@ async function webpackInstance(opts, shouldUseMem) {
140200 const interactive = require ( './interactive' ) ;
141201 return interactive ( options , outputOptions , processingErrors , shouldUseMem ) ;
142202 }
143-
144- compiler . hooks . beforeRun . tap ( 'webpackProgress' , compilation => {
145- if ( outputOptions . progress ) {
146- let tmp_msg ;
147- const defaultProgressPluginHandler = ( percent , msg , addInfo ) => {
148- percent = Math . floor ( percent * 100 ) ;
149- if ( percent === 100 ) {
150- msg = 'Compilation completed' ;
151- }
152-
153- if ( msg && tmp_msg != msg ) {
154- process . cliLogger . info ( percent + '% ' + msg ) ;
155- }
156- tmp_msg = msg ;
157- } ;
158- if ( ! progressPluginExists ) {
159- new ProgressPlugin ( defaultProgressPluginHandler ) . apply ( compiler ) ;
160- } else {
161- if ( ! progressPluginExists . handler ) {
162- options . plugins = options . plugins . filter ( e => e !== progressPluginExists ) ;
163- Object . keys ( progressPluginExists ) . map ( opt => {
164- ProgressPlugin . defaultOptions [ opt ] = progressPluginExists [ opt ] ;
165- } ) ;
166- new ProgressPlugin ( defaultProgressPluginHandler ) . apply ( compiler ) ;
167- } else {
168- progressPluginExists . apply ( compiler ) ;
169- }
170- }
171- }
172- } ) ;
173-
174- if ( outputOptions . infoVerbosity === 'verbose' ) {
175- if ( outputOptions . watch ) {
176- compiler . hooks . watchRun . tap ( 'WebpackInfo' , compilation => {
177- const compilationName = compilation . name ? compilation . name : '' ;
178- process . cliLogger . info ( 'Compilation ' + compilationName + ' starting…' ) ;
179- } ) ;
180- } else {
181- compiler . hooks . beforeRun . tap ( 'WebpackInfo' , compilation => {
182- const compilationName = compilation . name ? compilation . name : '' ;
183- process . cliLogger . info ( 'Compilation ' + compilationName + ' starting…' ) ;
184- } ) ;
185- }
186- compiler . hooks . done . tap ( 'WebpackInfo' , compilation => {
187- const compilationName = compilation . name ? compilation . name : '' ;
188- process . cliLogger . info ( 'Compilation ' + compilationName + ' finished' ) ;
189- } ) ;
203+ if ( compiler . compilers ) {
204+ compiler . compilers . forEach ( ( comp , idx ) => {
205+ setUpHookForCompiler ( comp , outputOptions , options [ idx ] ) ;
206+ } )
207+ } else {
208+ setUpHookForCompiler ( compiler , outputOptions , options ) ;
190209 }
210+
191211 if ( outputOptions . watch ) {
192212 const watchOptions = outputOptions . watchOptions || { } ;
193213 if ( watchOptions . stdin ) {
0 commit comments