Skip to content

Commit

Permalink
Run compiler in nextTick when callback provided
Browse files Browse the repository at this point in the history
  • Loading branch information
piecyk committed Oct 22, 2020
1 parent a377559 commit 02337bc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ ((
if (callback) {
try {
const { compiler, watch, watchOptions } = create();
if (watch) {
compiler.watch(watchOptions, callback);
} else {
compiler.run((err, stats) => {
compiler.close(err2 => {
callback(err || err2, stats);
process.nextTick(() => {
if (watch) {
compiler.watch(watchOptions, callback);
} else {
compiler.run((err, stats) => {
compiler.close(err2 => {
callback(err || err2, stats);
});
});
});
}
}
});
return compiler;
} catch (err) {
process.nextTick(() => callback(err));
Expand Down

0 comments on commit 02337bc

Please sign in to comment.