From 9d1f986a043f427b07890f52d46e49ff1352de93 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Mon, 18 Dec 2017 13:42:02 +0200 Subject: [PATCH] refactor: Show watch state messages only when webpack is watching 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. --- plugins/WatchStateLoggerPlugin.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/WatchStateLoggerPlugin.ts b/plugins/WatchStateLoggerPlugin.ts index 934e51f8..0c0c8b65 100644 --- a/plugins/WatchStateLoggerPlugin.ts +++ b/plugins/WatchStateLoggerPlugin.ts @@ -9,15 +9,22 @@ export enum messages { * So the {N} CLI can get some idea when compilation completes. */ export class WatchStateLoggerPlugin { + isRunningWatching: boolean; apply(compiler) { + const plugin = this; compiler.plugin("watch-run", function(compiler, callback) { - console.log(messages.changeDetected); + plugin.isRunningWatching = true; + if (plugin.isRunningWatching) { + console.log(messages.changeDetected); + } process.send && process.send(messages.changeDetected, error => null); callback(); }); compiler.plugin("after-emit", function(compilation, callback) { callback(); - console.log(messages.compilationComplete); + if (plugin.isRunningWatching) { + console.log(messages.compilationComplete); + } process.send && process.send(messages.compilationComplete, error => null); }); }