@@ -445,13 +445,22 @@ class Server {
445
445
const compilerOptions = this . getCompilerOptions ( ) ;
446
446
// TODO remove `{}` after drop webpack v4 support
447
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 ,
456
+ } ;
448
457
const defaultOptionsForStatic = {
449
458
directory : path . join ( process . cwd ( ) , "public" ) ,
450
459
staticOptions : { } ,
451
460
publicPath : [ "/" ] ,
452
461
serveIndex : { icons : true } ,
453
462
// Respect options from compiler watchOptions
454
- watch : watchOptions ,
463
+ watch : defaultWatchOptions ,
455
464
} ;
456
465
457
466
if ( typeof options . allowedHosts === "undefined" ) {
@@ -954,6 +963,11 @@ class Server {
954
963
// ensure that watch is an object if true
955
964
if ( staticOption . watch === true ) {
956
965
staticOption . watch = defaultOptionsForStatic . watch ;
966
+ } else if ( typeof staticOption . watch === "object" ) {
967
+ staticOption . watch = {
968
+ ...defaultOptionsForStatic . watch ,
969
+ ...staticOption . watch ,
970
+ } ;
957
971
}
958
972
959
973
// ensure that serveIndex is an object if true
@@ -964,7 +978,9 @@ class Server {
964
978
}
965
979
966
980
if ( typeof options . watchFiles === "string" ) {
967
- options . watchFiles = [ { paths : options . watchFiles , options : { } } ] ;
981
+ options . watchFiles = [
982
+ { paths : options . watchFiles , options : defaultWatchOptions } ,
983
+ ] ;
968
984
} else if (
969
985
typeof options . watchFiles === "object" &&
970
986
options . watchFiles !== null &&
@@ -973,16 +989,25 @@ class Server {
973
989
options . watchFiles = [
974
990
{
975
991
paths : options . watchFiles . paths ,
976
- options : options . watchFiles . options || { } ,
992
+ options : {
993
+ ...defaultWatchOptions ,
994
+ ...( options . watchFiles . options || { } ) ,
995
+ } ,
977
996
} ,
978
997
] ;
979
998
} else if ( Array . isArray ( options . watchFiles ) ) {
980
999
options . watchFiles = options . watchFiles . map ( ( item ) => {
981
1000
if ( typeof item === "string" ) {
982
- return { paths : item , options : { } } ;
1001
+ return { paths : item , options : defaultWatchOptions } ;
983
1002
}
984
1003
985
- return { paths : item . paths , options : item . options || { } } ;
1004
+ return {
1005
+ paths : item . paths ,
1006
+ options : {
1007
+ ...defaultWatchOptions ,
1008
+ ...( item . options || { } ) ,
1009
+ } ,
1010
+ } ;
986
1011
} ) ;
987
1012
} else {
988
1013
options . watchFiles = [ ] ;
@@ -2128,7 +2153,6 @@ class Server {
2128
2153
// duplicate the same massaging of options that watchpack performs
2129
2154
// https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js#L49
2130
2155
// this isn't an elegant solution, but we'll improve it in the future
2131
- // eslint-disable-next-line no-undefined
2132
2156
const usePolling =
2133
2157
typeof watchOptions . usePolling !== "undefined"
2134
2158
? watchOptions . usePolling
@@ -2143,12 +2167,7 @@ class Server {
2143
2167
undefined ;
2144
2168
2145
2169
const finalWatchOptions = {
2146
- ignoreInitial : true ,
2147
- persistent : true ,
2148
- followSymlinks : false ,
2149
- atomic : false ,
2150
- alwaysStat : true ,
2151
- ignorePermissionErrors : true ,
2170
+ ...watchOptions ,
2152
2171
ignored : watchOptions . ignored ,
2153
2172
usePolling,
2154
2173
interval,
0 commit comments