2015-12-02 57 views
0

時間我一直在使用大口建立的設置和我用chokidar聽文件更改減慢:chokidar每一個觀看文件被更改

var buildWatcher = chokidar.watch(paths, { ignoreInitial: true }); 

buildWatcher 
    .on('add', function(filePath) { 
     gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' add')); 
     gulp.start(key + suffix); 
    }) 
    .on('change', function(filePath) { 
     gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' change')); 
     gulp.start(key + suffix); 
    }) 
    .on('unlink', function(filePath) { 
     gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' unlink')); 
     gulp.start(key + suffix); 
    }); 

我有一個問題掙扎,就像一個內存泄漏或某事,即:每次保存文件時,監視進程佔用更多資源(任務管理器中的CPU),因此整個啓動任務需要更長的時間。啓動新的gulp時,最初任務運行平穩,CPU使用率低,啓動的任務需要幾毫秒才能執行。但幾次保存(即使是同一個文件),CPU使用率會在幾秒鐘內上升到100%。

我試圖切換到gulp.watch(3.9):

gulp.watch(paths, function(event) { 
    gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(event.path) + ' ' + event.type)); 
    gulp.start(key + suffix); 
}).on('error', function(error) { 
    gulpUtil.log(error); 
}); 

,在這裏我沒有這個問題。但是gulp.watch不支持監聽新文件,這就是爲什麼我不想使用chokidar。

你知道可能是chokidar性能問題背後的問題嗎?如何診斷?

感謝

回答

0

我不知道chokidar的表現,但我會建議你使用gulp-watch

請注意,您需要的是絕對路徑。

檢查爲什麼gulp.watch不支持新的/刪除的文件here

+0

最初我使用了gulp-watch,但是我遇到了同樣的性能問題,因爲gulp-watch正在使用chokidar。 – dragonfly

+0

我有一個非常複雜的設置使用gulp手錶,並經歷零性能問題。堰。我正在用不同的觀察者觀看6個不同的文件夾......也許你的問題在別的地方。 – avcajaraville

+0

似乎我不是唯一一個遇到它的人:https://github.com/paulmillr/chokidar/issues/328 – dragonfly