File tree 1 file changed +30
-4
lines changed
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
72
72
? ( process . env . WEBPACK_DEV_SERVER_PACKAGE as string )
73
73
: "webpack-dev-server" ;
74
74
75
+ const EXIT_SIGNALS = [ "SIGINT" , "SIGTERM" ] ;
76
+
75
77
interface Information {
76
78
Binaries ?: string [ ] ;
77
79
Browsers ?: string [ ] ;
@@ -2532,11 +2534,35 @@ class WebpackCLI implements IWebpackCLI {
2532
2534
: compiler . options . watch ,
2533
2535
) ;
2534
2536
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 ) ;
2538
2558
} ) ;
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
+ }
2540
2566
}
2541
2567
}
2542
2568
}
You can’t perform that action at this time.
0 commit comments