Hi @sokra. I’m making https://github.com/s-panferov/awesome-typescript-loader and I need some way to detect if webpack is working in --watch
mode or not (without plugins). I need this because I need to know if I should kill a spawned child_process
or not.
Right now I’m doing something like:
function isWatching(compiler) {
return compiler.options.watch || compiler.outputFileSystem.constructor.name === 'MemoryFileSystem';
}
But in doesn’t seems to work in the latest webpack@beta
. Can you please advise some reliable solution?
Right now the only way I see is to use a compiler plugin:
export const WatchModeSymbol = Symbol('WatchMode');
export class DetectWatchPlugin {
apply(compiler) {
compiler.plugin("run", function(params, callback) {
compiler[WatchModeSymbol] = false;
callback();
});
compiler.plugin("watch-run", function(params, callback) {
compiler[WatchModeSymbol] = true;
callback();
});
}
}
I also need this for the elm-webpack-loader
I’m saying internal implementation from core, IE new feature
@TheAifam5 I just want to be able to understand this from a loader, without requiring user to install a compiler plugin just for this.
@renatoagds
Looks need add
isWatch
(maybe better name) withfalse/true
(false
by default) toCompiler
https://github.com/webpack/webpack/blob/master/lib/Compiler.js and settrue
here https://github.com/webpack/webpack/blob/master/lib/Watching.js#L40