1
1
const webpack = require ( 'webpack' ) ;
2
2
const logger = require ( './logger' ) ;
3
+ const { cyanBright, greenBright } = require ( 'chalk' ) ;
3
4
const { CompilerOutput } = require ( './CompilerOutput' ) ;
4
5
5
6
class Compiler {
@@ -15,17 +16,26 @@ class Compiler {
15
16
16
17
compilation . hooks . beforeRun . tap ( 'webpackProgress' , ( ) => {
17
18
if ( outputOptions . progress ) {
18
- let tmpMsg ;
19
+ process . stdout . write ( '\n' ) ;
19
20
const defaultProgressPluginHandler = ( percent , msg ) => {
20
21
percent = Math . floor ( percent * 100 ) ;
21
- if ( percent === 100 ) {
22
- msg = 'Compilation completed' ;
22
+ process . stdout . clearLine ( ) ;
23
+ process . stdout . cursorTo ( 0 ) ;
24
+ if ( percent !== undefined ) {
25
+ process . stdout . write ( ' (' ) ;
26
+ for ( let i = 0 ; i <= 100 ; i += 10 ) {
27
+ if ( i <= percent ) {
28
+ process . stdout . write ( greenBright ( '#' ) ) ;
29
+ } else {
30
+ process . stdout . write ( '#' ) ;
31
+ }
32
+ }
33
+ process . stdout . write ( `) ${ percent } % : ` ) ;
34
+ process . stdout . write ( `${ cyanBright ( msg ) } ` ) ;
35
+ if ( percent === 100 ) {
36
+ process . stdout . write ( `${ cyanBright ( 'Complilation completed\n' ) } ` ) ;
37
+ }
23
38
}
24
-
25
- if ( msg && tmpMsg != msg ) {
26
- logger . info ( percent + '% ' + msg ) ;
27
- }
28
- tmpMsg = msg ;
29
39
} ;
30
40
if ( ! progressPluginExists ) {
31
41
new ProgressPlugin ( defaultProgressPluginHandler ) . apply ( compilation ) ;
0 commit comments