@@ -444,16 +444,49 @@ class Server {
444
444
445
445
const compilerOptions = this . getCompilerOptions ( ) ;
446
446
// TODO remove `{}` after drop webpack v4 support
447
- const watchOptions = compilerOptions . watchOptions || { } ;
448
- const defaultWatchOptions = {
449
- ignoreInitial : true ,
450
- persistent : true ,
451
- followSymlinks : false ,
452
- atomic : false ,
453
- alwaysStat : true ,
454
- ignorePermissionErrors : true ,
455
- ...watchOptions ,
447
+ const compilerWatchOptions = compilerOptions . watchOptions || { } ;
448
+
449
+ const getDefaultWatchOptions = ( watchOptions = { } ) => {
450
+ // duplicate the same massaging of options that watchpack performs
451
+ // https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js#L49
452
+ // this isn't an elegant solution, but we'll improve it in the future
453
+ const usePolling =
454
+ typeof watchOptions . usePolling !== "undefined"
455
+ ? watchOptions . usePolling
456
+ : Boolean ( watchOptions . poll ) ;
457
+
458
+ const interval =
459
+ // eslint-disable-next-line no-nested-ternary
460
+ typeof watchOptions . interval !== "undefined"
461
+ ? watchOptions . interval
462
+ : typeof watchOptions . poll === "number"
463
+ ? watchOptions . poll
464
+ : // eslint-disable-next-line no-undefined
465
+ undefined ;
466
+
467
+ const finalWatchOptions = {
468
+ ignoreInitial : true ,
469
+ persistent : true ,
470
+ followSymlinks : false ,
471
+ atomic : false ,
472
+ alwaysStat : true ,
473
+ ignorePermissionErrors : true ,
474
+ ...compilerWatchOptions ,
475
+ ...watchOptions ,
476
+ ignored : watchOptions . ignored ,
477
+ usePolling,
478
+ interval,
479
+ } ;
480
+
481
+ if ( finalWatchOptions . poll ) {
482
+ delete finalWatchOptions . poll ;
483
+ }
484
+
485
+ return finalWatchOptions ;
456
486
} ;
487
+
488
+ const defaultWatchOptions = getDefaultWatchOptions ( ) ;
489
+
457
490
const defaultOptionsForStatic = {
458
491
directory : path . join ( process . cwd ( ) , "public" ) ,
459
492
staticOptions : { } ,
@@ -965,8 +998,7 @@ class Server {
965
998
staticOption . watch = defaultOptionsForStatic . watch ;
966
999
} else if ( typeof staticOption . watch === "object" ) {
967
1000
staticOption . watch = {
968
- ...defaultOptionsForStatic . watch ,
969
- ...staticOption . watch ,
1001
+ ...getDefaultWatchOptions ( staticOption . watch ) ,
970
1002
} ;
971
1003
}
972
1004
@@ -990,8 +1022,7 @@ class Server {
990
1022
{
991
1023
paths : options . watchFiles . paths ,
992
1024
options : {
993
- ...defaultWatchOptions ,
994
- ...( options . watchFiles . options || { } ) ,
1025
+ ...getDefaultWatchOptions ( options . watchFiles . options || { } ) ,
995
1026
} ,
996
1027
} ,
997
1028
] ;
@@ -1004,8 +1035,7 @@ class Server {
1004
1035
return {
1005
1036
paths : item . paths ,
1006
1037
options : {
1007
- ...defaultWatchOptions ,
1008
- ...( item . options || { } ) ,
1038
+ ...getDefaultWatchOptions ( item . options || { } ) ,
1009
1039
} ,
1010
1040
} ;
1011
1041
} ) ;
@@ -2150,35 +2180,8 @@ class Server {
2150
2180
}
2151
2181
2152
2182
watchFiles ( watchPath , watchOptions ) {
2153
- // duplicate the same massaging of options that watchpack performs
2154
- // https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js#L49
2155
- // this isn't an elegant solution, but we'll improve it in the future
2156
- const usePolling =
2157
- typeof watchOptions . usePolling !== "undefined"
2158
- ? watchOptions . usePolling
2159
- : Boolean ( watchOptions . poll ) ;
2160
- const interval =
2161
- // eslint-disable-next-line no-nested-ternary
2162
- typeof watchOptions . interval !== "undefined"
2163
- ? watchOptions . interval
2164
- : typeof watchOptions . poll === "number"
2165
- ? watchOptions . poll
2166
- : // eslint-disable-next-line no-undefined
2167
- undefined ;
2168
-
2169
- const finalWatchOptions = {
2170
- ...watchOptions ,
2171
- ignored : watchOptions . ignored ,
2172
- usePolling,
2173
- interval,
2174
- } ;
2175
-
2176
- if ( finalWatchOptions . poll ) {
2177
- delete finalWatchOptions . poll ;
2178
- }
2179
-
2180
2183
const chokidar = require ( "chokidar" ) ;
2181
- const watcher = chokidar . watch ( watchPath , finalWatchOptions ) ;
2184
+ const watcher = chokidar . watch ( watchPath , watchOptions ) ;
2182
2185
2183
2186
// disabling refreshing on changing the content
2184
2187
if ( this . options . liveReload ) {
0 commit comments