Getting started
This page builds a Fable project from nothing and runs a counter in the browser.
Requirements
- .NET SDK 8.0 or later
- Node.js 20.19 or later
Set up the project
Create the project
Terminal dotnet new console -lang F# -o MyApp cd MyAppInstall Fable
The F# to JavaScript compiler, as a local tool.
Terminal dotnet new tool-manifest dotnet tool install fableAdd the packages
They are in beta, so
--prereleaseis required.Terminal dotnet add package Fable.Ripple --prerelease dotnet add package Fable.Ripple.Dom --prereleaseAdd Vite
It serves the compiled output during development and bundles it for production.
Terminal npm init -y npm install --save-dev viteSet the package type to
module.package.json { "type": "module" }Add the host page
Fable writes a
.jsfile next to each.fsfile, soProgram.fsbecomesProgram.fs.js.index.html <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>MyApp</title> </head> <body> <div id="root"></div> <script type="module" src="/Program.fs.js"></script> </body> </html><div id="root">is the element the app mounts into. Use any id you like, as long as it matches the one in the next step.Replace the contents of
Program.fsProgram.fs module Program open Fable.Ripple open Fable.Ripple.Dom let count = Var.create 0 let view = Html.div [ Html.button [ on.click (fun _ -> count.Value <- count.Value + 1) Html.text "Count" ] Html.output count ] Html.mount "root" viewHtml.mountrenders an item into the element with the given id.Run it
Fable watches the F# sources and Vite serves the result, so this takes two terminals.
Terminal 1 dotnet fable watchTerminal 2 npx viteOpen the address Vite prints. Click the button and the number changes. Editing
Program.fsrecompiles it and reloads the page.
Build for production
dotnet fable
npx vite build
The bundle is written to dist/.
Generated files
Fable's output sits next to the sources:
*.fs.js
Next steps
- Fable.Ripple - sources, derived signals, effects and batching.
- Fable.Ripple.Dom - elements, attributes, events and bindings. The examples on those pages compile and run in the page.
- Fable.UrlParser - typed routes from URLs.
- Fable.Ripple.Form - typed forms, one Var per field.