diff --git a/README.md b/README.md
index c99907d..303368e 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,13 @@ Show the cursor. This can be useful when a CLI accepts input from a user.
Auto clear console when compile is finished.
+### `done`
+ - Type: `Function(sharedState, ctx)`
+
+A function that will be called when **all** builds are finished.
+
+This function can optionally return `false` as a signal to stop rendering and printing profile stats.
+
Maintainers
diff --git a/src/index.js b/src/index.js
index 61f4e35..a029bcb 100644
--- a/src/index.js
+++ b/src/index.js
@@ -23,6 +23,7 @@ const defaults = {
clear: true,
showCursor: false,
enabled: process.stdout.isTTY && !isCI,
+ done: null,
};
export default class WebpackBarPlugin extends webpack.ProgressPlugin {
@@ -76,6 +77,18 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
return;
}
+ if (Object.values(sharedState).find((s) => s.isRunning)) {
+ return;
+ }
+
+ if (typeof this.options.done === 'function') {
+ const result = this.options.done(sharedState, this);
+ if (result === false) {
+ // Special signal to do nothing
+ return;
+ }
+ }
+
this.render();
if (this.options.profile) {
diff --git a/test/basic.test.js b/test/basic.test.js
index 2868906..70b95cb 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -16,6 +16,8 @@ describe('webpackbar', () => {
const logUpdate = mockLogUpdate();
test('compile', async () => {
+ const done = jest.fn();
+
const compiler = webpack(
basicConfig.from({
name: 'test1',
@@ -23,6 +25,7 @@ describe('webpackbar', () => {
profile: true,
color: '#202020',
logUpdate,
+ done,
})
);
@@ -31,6 +34,7 @@ describe('webpackbar', () => {
expect(stats.hasErrors()).toBe(false);
expect(stats.hasWarnings()).toBe(false);
+ expect(done).toHaveBeenCalledTimes(1);
});
test('logUpdate', () => {