@@ -119,6 +119,7 @@ if(argv.alias) {
119119}
120120
121121var webpack = require ( "../lib/webpack.js" ) ;
122+ var formatOutput = require ( "../lib/formatOutput.js" ) ;
122123
123124function c ( str ) {
124125 return argv . colors ? str : "" ;
@@ -191,92 +192,11 @@ if(!output) {
191192 if ( argv . json )
192193 console . log ( util . inspect ( stats , false , 10 , argv . colors ) ) ;
193194 else {
194- console . log ( "Hash: " + c ( "\033[1m" ) + stats . hash + c ( "\033[22m" ) ) ;
195- console . log ( "Chunks: " + c ( "\033[1m" ) + stats . chunkCount + c ( "\033[22m" ) ) ;
196- console . log ( "Modules: " + c ( "\033[1m" ) + stats . modulesCount + c ( "\033[22m" ) ) ;
197- console . log ( "Modules including duplicates: " + c ( "\033[1m" ) + stats . modulesIncludingDuplicates + c ( "\033[22m" ) ) ;
198- console . log ( "Modules pre chunk: " + c ( "\033[1m" ) + stats . modulesPerChunk + c ( "\033[22m" ) ) ;
199- console . log ( "Modules first chunk: " + c ( "\033[1m" ) + stats . modulesFirstChunk + c ( "\033[22m" ) ) ;
200- if ( stats . fileSizes )
201- Object . keys ( stats . fileSizes ) . reverse ( ) . forEach ( function ( file ) {
202- console . log ( c ( "\033[1m" ) + sprintf ( "%" + ( 5 + options . output . length ) + "s" , file ) + c ( "\033[22m" ) + ": " + c ( "\033[1m" ) + sprintf ( "%8d" , stats . fileSizes [ file ] ) + c ( "\033[22m" ) + " characters" ) ;
203- } ) ;
204- var cwd = process . cwd ( ) ;
205- var cwdParent = path . dirname ( cwd ) ;
206- var buildins = path . join ( __dirname , ".." ) ;
207- cwd = cwd . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
208- cwd = new RegExp ( "^" + cwd + "|(!)" + cwd , "g" ) ;
209- var buildinsAsModule = cwd . test ( buildins ) ;
210- cwdParent = cwdParent . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
211- cwdParent = new RegExp ( "^" + cwdParent + "|(!)" + cwdParent , "g" ) ;
212- buildins = buildins . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
213- buildins = new RegExp ( "^" + buildins + "|(!)" + buildins , "g" ) ;
214- var node_modulesRegExpA = / \/ n o d e _ m o d u l e s \/ / g;
215- var node_modulesRegExpB = / \\ n o d e _ m o d u l e s \\ / g;
216- var index_jsRegExp = / [ \\ \/ ] i n d e x .j s ! / g;
217- function compressFilename ( filename ) {
218- if ( ! filename )
219- return filename ;
220- if ( buildinsAsModule )
221- filename = filename . replace ( buildins , "!(webpack)" ) ;
222- filename = filename . replace ( cwd , "!." ) ;
223- if ( ! buildinsAsModule )
224- filename = filename . replace ( buildins , "!(webpack)" ) ;
225- filename = filename . replace ( node_modulesRegExpA , "/~/" ) ;
226- filename = filename . replace ( node_modulesRegExpB , "\\~\\" ) ;
227- filename = filename . replace ( index_jsRegExp , "!" ) ;
228- return filename . replace ( / ^ ! | ! $ / , "" ) ;
229- }
230- if ( stats . fileModules ) {
231- console . log ( ) ;
232- console . log ( " <id> <size> <filename>" ) ;
233- if ( argv . verbose )
234- console . log ( " <reason> from <filename>" ) ;
235- Object . keys ( stats . fileModules ) . reverse ( ) . forEach ( function ( file ) {
236- console . log ( c ( "\033[1m\033[32m" ) + file + c ( "\033[39m\033[22m" ) ) ;
237- var modules = stats . fileModules [ file ] ;
238- if ( argv [ "by-size" ] )
239- modules . sort ( function ( a , b ) {
240- return b . size - a . size ;
241- } ) ;
242- modules . forEach ( function ( module ) {
243- console . log ( " " + c ( "\033[1m" ) + sprintf ( "%3s" , module . id + "" ) + " " + ( typeof module . size === "number" ? sprintf ( "%9s" , Math . round ( module . size ) + "" ) : " " ) + " " +
244- ( compressFilename ( module . filename ) ||
245- ( module . dirname && ( "[context] " + compressFilename ( module . dirname ) ) ) ||
246- "[unknown]" ) + c ( "\033[22m" ) ) ;
247- if ( argv . verbose ) {
248- module . reasons . forEach ( function ( reason ) {
249- switch ( reason . type ) {
250- case "require" :
251- console . log ( " " + c ( "\033[36m" ) + "require (" + reason . count + "x) from " + compressFilename ( reason . filename ) + c ( "\033[39m" ) ) ;
252- break ;
253- case "context" :
254- console . log ( " " + c ( "\033[90m" ) + "context from " + compressFilename ( reason . filename ) + c ( "\033[39m" ) ) ;
255- break ;
256- case "async require" :
257- console . log ( " " + c ( "\033[35m" ) + "async require (" + reason . count + "x) from " + compressFilename ( reason . filename ) + c ( "\033[39m" ) ) ;
258- break ;
259- case "async context" :
260- console . log ( " " + c ( "\033[35ma" ) + "sync context from " + compressFilename ( reason . filename ) + c ( "\033[39m" ) ) ;
261- break ;
262- default :
263- console . log ( " " + c ( "\033[31m" ) + reason . type + c ( "\033[39m" ) ) ;
264- }
265- } ) ;
266- }
267- } ) ;
268- } ) ;
269- }
270- if ( stats . warnings ) {
271- stats . warnings . forEach ( function ( warning ) {
272- console . log ( c ( "\033[1m\033[33m" ) + "WARNING: " + warning + c ( "\033[39m\033[22m" ) ) ;
273- } ) ;
274- }
275- if ( stats . errors ) {
276- stats . errors . forEach ( function ( error ) {
277- console . log ( c ( "\033[1m\033[31m" ) + "ERROR: " + error + c ( "\033[39m\033[22m" ) ) ;
278- } ) ;
279- }
195+ console . log ( formatOutput ( stats , {
196+ colors : argv . colors ,
197+ "by-size" : argv [ "by-size" ] ,
198+ verbose : argv . verbose
199+ } ) ) ;
280200 }
281201 } ) ;
282202}
0 commit comments