Watching file changes with NPM Scripts

added by JavaScript Kicks
12/29/2016 7:11:28 AM

1443 Views

I love removing dependencies from my project, so I was sold on building with npm scripts right away. I was a tad disappointed, though, when I saw that there isn't built-in support for watching files for changes.


2 comments

Kalin Chernev
12/30/2016 6:45:17 PM
It looks like a good idea and most certainly good cause to keep down the number of dependencies. I think there might be 2 main problems with this approach: 1) The fs.watch documentation points out an inconsistent behaviors and warns that it doesn't work in Linux: https://nodejs.org/docs/latest/api/fs.html#fs_caveats 2) The input filename parameter is a string, but not a blob, so this has to be defined very precisely.

css_mike
12/30/2016 11:51:07 PM
Both good callouts. A shame that the linux implementation lacks parity. Regarding the blob issue, you can work around it by watching a directory and then filtering the changed files with a regex, but at some point workarounds aren't worth it. Thanks for reading!