feat(watching): allow suspend compilation

This commit is contained in:
jkzing 2019-06-01 00:53:33 +08:00
parent 29068d39ce
commit df27a5e2bd
2 changed files with 27 additions and 1 deletions

View File

@ -18,6 +18,18 @@ class MultiWatching {
}
}
suspend() {
for (const watching of this.watchings) {
watching.suspend();
}
}
resume() {
for (const watching of this.watchings) {
watching.resume();
}
}
close(callback) {
asyncLib.forEach(
this.watchings,

View File

@ -13,6 +13,7 @@ class Watching {
this.handler = handler;
this.callbacks = [];
this.closed = false;
this.suspended = false;
if (typeof watchOptions === "number") {
this.watchOptions = {
aggregateTimeout: watchOptions
@ -133,7 +134,9 @@ class Watching {
this.compiler.fileTimestamps = fileTimestamps;
this.compiler.contextTimestamps = contextTimestamps;
this.compiler.removedFiles = removedFiles;
this._invalidate();
if (!this.suspended) {
this._invalidate();
}
},
(fileName, changeTime) => {
this.compiler.hooks.invalid.call(fileName, changeTime);
@ -166,6 +169,17 @@ class Watching {
}
}
suspend() {
this.suspended = true;
}
resume() {
if (this.suspended) {
this.suspended = false;
this._invalidate();
}
}
close(callback) {
const finalCallback = () => {
this.compiler.hooks.watchClose.call();