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