Skip to content

Commit 3973f6b

Browse files
author
Pooya Parsa
committed
feat: add compile stats to the sharedState
1 parent 37bf520 commit 3973f6b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
5858
return sharedState[this.options.name];
5959
}
6060

61+
apply(compiler) {
62+
super.apply(compiler);
63+
64+
const hook = (stats) => {
65+
this.state.stats = stats;
66+
if (!hasRunning()) {
67+
this.logUpdate.clear();
68+
this.done();
69+
}
70+
};
71+
72+
if (compiler.hooks) {
73+
compiler.hooks.done.tap('WebpackBar', hook);
74+
} else {
75+
compiler.plugin('done', hook);
76+
}
77+
}
78+
6179
done() {
6280
if (this.options.profile) {
6381
const stats = this.state.profile.getStats();
@@ -86,6 +104,7 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
86104

87105
if (!wasRunning && isRunning) {
88106
// Started
107+
delete this.state.stats;
89108
this.state.start = process.hrtime();
90109
if (this.options.minimal) {
91110
consola.info(`Compiling ${this.options.name}`);
@@ -110,12 +129,7 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
110129
this.state.profile.onRequest(this.state.request);
111130
}
112131

113-
if (hasRunning()) {
114-
this._render();
115-
} else {
116-
this.logUpdate.clear();
117-
this.done();
118-
}
132+
this._render();
119133
}
120134

121135
render() {

0 commit comments

Comments
 (0)