Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit ab3ae97

Browse files
PanayotCankovVasil Chimev
authored and
Vasil Chimev
committed
refactor: Show watch state messages only when webpack is watching (#358)
When run with `webpack --watch` the WatchStateLoggerPlugin will print console messages with the watcher state. When run with `webpack` (no --watch) the WatchStateLoggerPlugin will be silent in the console, but still notify via IPC.
1 parent dc777a2 commit ab3ae97

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plugins/WatchStateLoggerPlugin.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@ export enum messages {
99
* So the {N} CLI can get some idea when compilation completes.
1010
*/
1111
export class WatchStateLoggerPlugin {
12+
isRunningWatching: boolean;
1213
apply(compiler) {
14+
const plugin = this;
1315
compiler.plugin("watch-run", function(compiler, callback) {
14-
console.log(messages.changeDetected);
16+
plugin.isRunningWatching = true;
17+
if (plugin.isRunningWatching) {
18+
console.log(messages.changeDetected);
19+
}
1520
process.send && process.send(messages.changeDetected, error => null);
1621
callback();
1722
});
1823
compiler.plugin("after-emit", function(compilation, callback) {
1924
callback();
20-
console.log(messages.compilationComplete);
25+
if (plugin.isRunningWatching) {
26+
console.log(messages.compilationComplete);
27+
}
2128
process.send && process.send(messages.compilationComplete, error => null);
2229
});
2330
}

0 commit comments

Comments
 (0)