Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ class Compiler extends Tapable {

/** @type {boolean} */
this.running = false;

/** @type {boolean} */
this.watchMode = false;
}

watch(watchOptions, handler) {
if (this.running) return handler(new ConcurrentCompilationError());

this.running = true;
this.watchMode = true;
this.fileTimestamps = new Map();
this.contextTimestamps = new Map();
return new Watching(this, watchOptions, handler);
Expand Down
1 change: 1 addition & 0 deletions lib/Watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class Watching {
const finalCallback = () => {
this.compiler.hooks.watchClose.call();
this.compiler.running = false;
this.compiler.watchMode = false;
if (callback !== undefined) callback();
};

Expand Down
22 changes: 22 additions & 0 deletions test/Compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,28 @@ describe("Compiler", () => {
});
});
});
it("should flag watchMode as true in watch", function(done) {
const compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
output: {
path: "/",
filename: "bundle.js"
}
});

compiler.outputFileSystem = new MemoryFs();

const watch = compiler.watch({}, err => {
if (err) return done(err);
expect(compiler.watchMode).toBeTruthy();
watch.close(() => {
expect(compiler.watchMode).toBeFalsy();
done();
});
});
});
it("should use cache on second run call", function(done) {
const compiler = webpack({
context: __dirname,
Expand Down