@@ -106,7 +106,8 @@ exports.run = (options) => {
106
106
107
107
if ( isGoingToStartServer ) {
108
108
let middlewareCache = { } ,
109
- promiseCache = { } ;
109
+ promiseCache = { } ,
110
+ watchCacheNames = { } ;
110
111
111
112
if ( middlewares ) {
112
113
middlewares . split ( '|' ) . forEach ( ( proName ) => {
@@ -227,7 +228,7 @@ exports.run = (options) => {
227
228
middleware ( req , res , next ) ;
228
229
} ) ;
229
230
// 检测config文件变化
230
- watchConfig ( project , middleware , middlewareCache , cacheId )
231
+ watchConfig ( project , middleware , cacheId )
231
232
} else {
232
233
next ( )
233
234
}
@@ -261,7 +262,7 @@ exports.run = (options) => {
261
262
resolve ( middleware ) ;
262
263
} ) ;
263
264
// 检测config文件变化
264
- watchConfig ( project , middleware , middlewareCache , projectName )
265
+ watchConfig ( project , middleware , projectName )
265
266
} else {
266
267
next ( )
267
268
}
@@ -331,12 +332,23 @@ exports.run = (options) => {
331
332
}
332
333
333
334
// 监测配置文件变化
334
- function watchConfig ( project , middleware , caches , cacheName ) {
335
- const projectConfigFilePath = sysPath . resolve ( project . config . _config . cwd , project . configFile )
336
- fs . watchFile ( projectConfigFilePath , { interval : 2000 } , ( ) => {
337
- caches [ cacheName ] = null
338
- UtilFs . deleteFolderRecursive ( project . cachePath , true )
339
- } ) ;
335
+ function watchConfig ( project , middleware , cacheName ) {
336
+ const cwdConfigPath = sysPath . resolve ( project . config . _config . cwd , project . configFile )
337
+
338
+ if ( watchCacheNames [ cwdConfigPath ] ) {
339
+ if ( watchCacheNames [ cwdConfigPath ] . indexOf ( cacheName ) === - 1 ) {
340
+ watchCacheNames [ cwdConfigPath ] . push ( cacheName )
341
+ }
342
+ } else {
343
+ watchCacheNames [ cwdConfigPath ] = [ cacheName ]
344
+
345
+ fs . watchFile ( cwdConfigPath , { interval : 2000 } , ( ) => {
346
+ watchCacheNames [ cwdConfigPath ] . map ( ( cacheName ) => {
347
+ middlewareCache [ cacheName ] = null
348
+ } )
349
+ UtilFs . deleteFolderRecursive ( project . cachePath , true )
350
+ } ) ;
351
+ }
340
352
}
341
353
}
342
354
} ;
0 commit comments