Search code examples
vagrantclojurescriptluminusfigwheel

Figwheel not hot reloading or updating on file save when using vagrant


When running figwheel from with a vagrant box it seems that file changes aren't noticed and as a result figwheel does not update/reload the page.


Solution

  • After spending hours trying to figure out what was going on it eventually came down to how figwheel detects file changes.

    To detect file changes figwheel uses the hawk library which in turn uses the operating system to that tell hawk the file has updated. Because vagrant defaults to using vboxsf there is no underlying update mechanism to provide updates that the file has changed, see here. To fix this we just need to tell figwheel, and thus hawk, to poll for file changes:

    :figwheel {:hawk-options {:watcher :polling}
    

    Just pop this in the your profile.clj and that will allow figwheel to see changes after the file has been saved, although it does take a while for the polling to pick up the changes so wait a little bit.

    This only however solves half of the problem because figwheel still requires an active websocket connection to actually push the code changes. This is complicated by the fact the a vagrant vm is a separate machine on the network and requires you expose this websocket to more than just localhost. This can be achieved by adding another key to the figwheel map in project.clj:

    :figwheel {:server-ip "0.0.0.0"}
    

    and then exposing the figwheel websocket port in the vagrantfile:

    config.vm.network "forwarded_port", guest: 3449, host: 3449
    

    and that should fix figwheel on vagrant!