@@ -121,23 +121,24 @@ export default class WebpackBarPlugin extends ProgressPlugin {
121
121
return globalStates [ this . options . name ] ;
122
122
}
123
123
124
+ _ensureState ( ) {
125
+ // Keep our state in shared object
126
+ if ( ! this . states [ this . options . name ] ) {
127
+ this . states [ this . options . name ] = {
128
+ ...DEFAULT_STATE ,
129
+ color : this . options . color ,
130
+ name : startCase ( this . options . name ) ,
131
+ } ;
132
+ }
133
+ }
134
+
124
135
apply ( compiler ) {
125
136
super . apply ( compiler ) ;
126
137
127
- // Initialize our state before actual build
128
- hook ( compiler , 'afterPlugins' , ( ) => {
129
- // Keep our state in shared object
130
- if ( ! this . states [ this . options . name ] ) {
131
- this . states [ this . options . name ] = {
132
- ...DEFAULT_STATE ,
133
- color : this . options . color ,
134
- name : startCase ( this . options . name ) ,
135
- } ;
136
- }
137
- } ) ;
138
-
139
138
// Hook into the compiler before a new compilation is created.
140
139
hook ( compiler , 'compile' , ( ) => {
140
+ this . _ensureState ( ) ;
141
+
141
142
Object . assign ( this . state , {
142
143
...DEFAULT_STATE ,
143
144
start : process . hrtime ( ) ,
@@ -148,6 +149,8 @@ export default class WebpackBarPlugin extends ProgressPlugin {
148
149
149
150
// Watch compilation has been invalidated.
150
151
hook ( compiler , 'invalid' , ( fileName , changeTime ) => {
152
+ this . _ensureState ( ) ;
153
+
151
154
this . callReporters ( 'change' , {
152
155
path : fileName ,
153
156
shortPath : shortenPath ( fileName ) ,
@@ -157,6 +160,8 @@ export default class WebpackBarPlugin extends ProgressPlugin {
157
160
158
161
// Compilation has completed
159
162
hook ( compiler , 'done' , ( stats ) => {
163
+ this . _ensureState ( ) ;
164
+
160
165
const time = prettyTime ( process . hrtime ( this . state . start ) , 2 ) ;
161
166
const hasErrors = stats . hasErrors ( ) ;
162
167
const status = hasErrors ? 'with some errors' : 'succesfuly' ;
0 commit comments