Telling Spring to watch certain directories/files

If you have some file or directory that should trigger a Spring reboot, tell Spring e.g. in config/spring.rb:

Spring.watch 'file.rb'
Spring.watch 'lib/templates'

However, Spring will silently drop paths that do not exist at the time calling #watch. Unless you restart Spring (thereby reloading the watch commands), it won't even watch them once they do exist.

Make sure the watchable paths exist before telling Spring to watch, e.g. with

FileUtils.touch 'file.rb'
FileUtils.mkdir_p 'lib/templates'
Spring.watch 'file.rb'
Spring.watch 'lib/templates'

For the curious, Spring::Watcher::Abstract#add is the culprit.

Dominik Schöler