.Net Core 2, Node.js, Yarn. Make sure you’ve got it all. Then just open shell and let’s type.
dotnet new -i SAFE.Template
dotnet new SAFE -lang 'F#' --Server suave --Fulma basic
Now you should have the following directory structure:
├───.paket └───src ├───Client │ ├───obj │ └───public │ └───Images ├───Server │ └───obj └───Shared
The template uses Paket - a typical replacement for NuGet package manager in the world of F#. Like it or not it works just fine.
It takes a while for the first time. Once it’s done it kicks off the server and a browser window navigating to
http://localhost:8080/. It displays a basic page with a counter we can increment and decrement.
./src/Client/Client.fs and find the following method:
let update (msg : Msg) (model : Model) : Model * Cmd<Msg> = let model' = match model, msg with | Some x, Increment -> Some (x + 1) | Some x, Decrement -> Some (x - 1) | None, Init (Ok x) -> Some x | _ -> None model', Cmd.none
Now change it to increment 7 and decrement 3 (or whatever) and save it. In the console you should see something like the following:
i ｢wdm｣: Compiling... Parsing ./Client/Client.fs... fable: Compiled Client.fs
And then boom, go to the browser, DO NOT reload the page, and enjoy your counter being broken.
It has been a very quick overview I hope you enjoyed. I believe SAFE stack not only can boost productivity but also is a milestone in making F# a popular rather than an exotic choice.
I like it much - we use it in the company I work for too. However, FAKE is undergoing a serious refactoring right now and the documentation is quite fragmented/incomplete. Unless you’re a researcher/fanatic I would not recommend to use it until it’s settled. ↩︎