Closed tumblingG closed 1 year ago
When I use the local proxy to access the local file, the js file will also trigger the update. Is the browser changing the file?
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.
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) => {
});
I monitor my engineering projects. When I opened the images folder of my project from windows D, the update automatically triggered, but I didn't actually change the images. And the js files sometimes update automatically even though I haven't changed anything, why?