File tree Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ const WEBPACK_DEV_SERVER_PACKAGE = WEBPACK_DEV_SERVER_PACKAGE_IS_CUSTOM
7272 ? ( process . env . WEBPACK_DEV_SERVER_PACKAGE as string )
7373 : "webpack-dev-server" ;
7474
75+ const EXIT_SIGNALS = [ "SIGINT" , "SIGTERM" ] ;
76+
7577interface Information {
7678 Binaries ?: string [ ] ;
7779 Browsers ?: string [ ] ;
@@ -2532,11 +2534,35 @@ class WebpackCLI implements IWebpackCLI {
25322534 : compiler . options . watch ,
25332535 ) ;
25342536
2535- if ( isWatch ( compiler ) && this . needWatchStdin ( compiler ) ) {
2536- process . stdin . on ( "end" , ( ) => {
2537- process . exit ( 0 ) ;
2537+ if ( isWatch ( compiler ) ) {
2538+ let needForceShutdown = false ;
2539+
2540+ EXIT_SIGNALS . forEach ( ( signal ) => {
2541+ const listener = ( ) => {
2542+ if ( needForceShutdown ) {
2543+ process . exit ( 0 ) ;
2544+ }
2545+
2546+ this . logger . info (
2547+ "Gracefully shutting down. To force exit, press ^C again. Please wait..." ,
2548+ ) ;
2549+
2550+ needForceShutdown = true ;
2551+
2552+ compiler . close ( ( ) => {
2553+ process . exit ( 0 ) ;
2554+ } ) ;
2555+ } ;
2556+
2557+ process . on ( signal , listener ) ;
25382558 } ) ;
2539- process . stdin . resume ( ) ;
2559+
2560+ if ( this . needWatchStdin ( compiler ) ) {
2561+ process . stdin . on ( "end" , ( ) => {
2562+ process . exit ( 0 ) ;
2563+ } ) ;
2564+ process . stdin . resume ( ) ;
2565+ }
25402566 }
25412567 }
25422568}
You can’t perform that action at this time.
0 commit comments