This template can be used to generate a simple web app with Fable.
You can find more templates by searching Fable.Template
packages in Nuget.
npm comes bundled with node.js, but we recommend to use at least npm 5. If you have npm installed, you can upgrade it by running
npm install -g npm
.
Although is not a Fable requirement, on macOS and Linux you'll need Mono for other F# tooling like Paket or editor support.
The project can be used by editors compatible with the new .fsproj format, like VS Code + Ionide, Emacs with fsharp-mode or Rider. Visual Studio for Mac is also compatible but in the current version the package auto-restore function conflicts with Paket so you need to disable it: Preferences > Nuget > General
.
In a terminal, run dotnet new -i Fable.Template::*
to install or update the template to the latest version.
In some shells you many need quotations:
dotnet new -i "Fable.Template::*"
. If you use dotnet SDK 2, you should only need to typedotnet new -i Fable.Template
.
In a terminal, run dotnet new fable
to create a project in the current directory. Type dotnet new fable -n MyApp
instead to create a subfolder named MyApp
and put the new project there.
The project will have the name of the directory. You may get some issues if the directory name contains some special characters like hyphens
In the commands below, yarn is the tool of choice. If you want to use npm, just replace
yarn
bynpm
in the commands.
yarn install
src
folder: cd src
dotnet restore
dotnet fable yarn-start
dotnet fable yarn-start
(ornpm-start
) is used to start the Fable daemon and run a script in package.json concurrently. It's a shortcut ofyarn-run [SCRIPT_NAME]
, e.g.dotnet fable yarn-run start
.
If you are using VS Code + Ionide, you can also use the key combination: Ctrl+Shift+B (Cmd+Shift+B on macOS) instead of typing the dotnet fable yarn-start
command. This also has the advantage that Fable-specific errors will be highlighted in the editor along with other F# errors.
Any modification you do to the F# code will be reflected in the web page after saving. When you want to output the JS code to disk, run dotnet fable yarn-build
and you'll get a minified JS bundle in the public
folder.
Paket is the package manager used for F# dependencies. It doesn't need a global installation, the binary is included in the .paket
folder. Other Paket related files are:
.fsproj
file.Paket dependencies will be installed in the
packages
directory. See Paket website for more info.
JS dependencies will be installed in
node_modules
. See yarn and/or npm websites for more info.
Webpack is a bundler, which links different JS sources into a single file making deployment much easier. It also offers other features, like a static dev server that can automatically refresh the browser upon changes in your code or a minifier for production release. Fable interacts with Webpack through the fable-loader
.
The template only contains two F# source files: the project (.fsproj) and a source file (.fs) in src
folder.
Check more Fable samples, use another template like Fable.Template.Elmish.React
or clone the fable-suave-scaffold.