Search code examples
.netf#suave

Reload Suave App on File Save


I've recently started with Suave; I setup a project using yeoman and the F# generator. To run the app, I build an executable using Fake and then run it. Whenever I change any of the app files, i.e. *.fs files, I have to repeat the process of building and running an executable.

Is there a better process for development, wherein the app rebuilds or reloads/restarts on file save?


Solution

  • The build script for the F# Snippets project does exactly this.

    The idea is that you have app.fsx file that defines a top-level WebPart named app. You can see the example for F# Snippets here. The app.fsx script file can also load other files, so you can structure your application in any way you need.

    The build.fsx build script then starts a server, monitors file system changes for your source code and app.fsx and reloads it using F# Compiler Service in the background and replaces the "currently loaded" server with the one obtained from the new app value.

    The only limitation of the current build script is that it does not correctly relcaim memory (it should probably be fixed by recreating F# Interactive Session in the build script) and so it runs out of memory after a larger number of reloads. But still, it makes the workflow much nicer!