@@ -16,6 +16,21 @@ const addDevServerEntrypoints = require('../lib/util/addDevServerEntrypoints');
16
16
const createDomain = require ( '../lib/util/createDomain' ) ; // eslint-disable-line
17
17
const createLog = require ( '../lib/createLog' ) ;
18
18
19
+ let server ;
20
+
21
+ [ 'SIGINT' , 'SIGTERM' ] . forEach ( ( sig ) => {
22
+ process . on ( sig , ( ) => {
23
+ if ( server ) {
24
+ server . close ( ( ) => {
25
+ process . exit ( ) ; // eslint-disable-line no-process-exit
26
+ } ) ;
27
+ }
28
+ else {
29
+ process . exit ( ) ; // eslint-disable-line no-process-exit
30
+ }
31
+ } ) ;
32
+ } ) ;
33
+
19
34
// Prefer the local installation of webpack-dev-server
20
35
if ( importLocal ( __filename ) ) {
21
36
debug ( 'Using local install of webpack-dev-server' ) ;
@@ -393,7 +408,6 @@ function startDevServer(webpackOptions, options) {
393
408
394
409
const suffix = ( options . inline !== false || options . lazy === true ? '/' : '/webpack-dev-server/' ) ;
395
410
396
- let server ;
397
411
try {
398
412
server = new Server ( compiler , options , log ) ;
399
413
} catch ( e ) {
@@ -405,14 +419,6 @@ function startDevServer(webpackOptions, options) {
405
419
throw e ;
406
420
}
407
421
408
- [ 'SIGINT' , 'SIGTERM' ] . forEach ( ( sig ) => {
409
- process . on ( sig , ( ) => {
410
- server . close ( ( ) => {
411
- process . exit ( ) ; // eslint-disable-line no-process-exit
412
- } ) ;
413
- } ) ;
414
- } ) ;
415
-
416
422
if ( options . socket ) {
417
423
server . listeningApp . on ( 'error' , ( e ) => {
418
424
if ( e . code === 'EADDRINUSE' ) {
0 commit comments