-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 964 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const ora = require('ora');
module.exports = class SimpleProgressPlugin {
constructor(options) {
this.options = options || {};
this.name = 'SimpleProgressPlugin';
}
apply(compiler) {
const {buildName, onlyWatch = false} = this.options;
if (!buildName) {
return;
}
const spinner = ora({
text: `Running ${buildName} build`,
discardStdin: false,
stream: process.stdout,
});
if (onlyWatch) {
compiler.hooks.invalid.tap(this.name, () => {
spinner.start();
});
} else {
compiler.hooks.thisCompilation.tap(this.name, () => {
spinner.start();
});
}
compiler.hooks.done.tap(this.name, () => {
spinner.succeed();
});
compiler.hooks.failed.tap(this.name, () => {
spinner.fail();
});
}
};