images update problem
Closed this issue · 3 comments
tumblingG commented
tumblingG commented
yuanchuan commented
There is nothing to do with node-watch
. Replacing watch
with fs.watch
would be the same.
When you open a directory your OS system may update some meta data of that directory. Since you're watching the whole directory recursively that callback will be triggered anyway. And sometimes the editors will save files silently even if the save
button isn't being touched.
yuanchuan commented
One way to avoid the blindly calling is to detect the file types which you're going to handle. For example, inside the callback function:
watch('somehere', {recursive: true}, (evt, pathname) => {
if (/\.png$/.test(pathname)) {
// do something
}
});
You can also increase the delay
so that the setTimeout
thing in your code would be unnecessary.
watch('somewhere', { recursive: true, delay: 1000 }, (evt, pathname) => {
});