Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: graceful exit terminal #3075

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,27 @@ class WebpackCLI {
return;
}

const signals = ["SIGINT", "SIGTERM"];
let needForceShutdown = false;

signals.forEach((signal) => {
const listener = () => {
if (needForceShutdown) {
process.exit();
}

this.logger.info("Gracefully shutting down. To force exit, press ^C again. Please wait...");

needForceShutdown = true;

compiler.close(() => {
process.exit();
});
};

process.on(signal, listener);
});
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved

const isWatch = (compiler) =>
compiler.compilers
? compiler.compilers.some((compiler) => compiler.options.watch)
Expand Down