My personal favorite for watching files and running context sensitive commands is to use the lovely filewatcher CLI utility written in Ruby.

gem install filewatcher
gem install filewatcher-cli

This can then be used with:

filewatcher '**/*.js' 'node $FILENAME'

However this hasn’t been updated in a while now and fails on newer versions of Ruby. So now I use watchexec.

cargo install watchexec-cli
watchexec -w source/f2py 'make html'