canislupaster / Tome

Searches through things
0 stars 0 forks source link

Build Instructions

This is a fable app made with F#. Fable is a f# to js transpiler.

Requirements

Editor

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.

Installing the template

In a terminal, run dotnet new -i Fable.Template to install or update the template to the latest version.

Creating a new project with the 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

Building and running the app

In the commands below, yarn is the tool of choice. If you want to use npm, just replace yarn by npm in the commands.

Check the scripts section in package.json for more info. If you are using VS Code + Ionide, you can also use F5 or Ctrl+Shift+B (Cmd+Shift+B on macOS) instead of typing yarn start. With this Fable-specific errors will be highlighted in the editor along with other F# errors. See Debugging in VS Code below.

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 yarn build and you'll get your frontend files ready for deployment in the build folder.

Debugging in VS Code

JS Output

This template uses babel-preset-env to output JS code whose syntax is compatible with a wide range of browsers. Currently it's set to support browsers with at least 1% of market share. You can replace this in babelOptions within tools/webpack.config.common.js with a query understood by browserl.ist.

To replace objects and APIs that may be missing in old browsers, the final index.html will include a request to cdn.polyfill.io.

Project structure

Paket

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:

Paket dependencies will be installed in a cache. See Paket website for more info.

yarn

JS dependencies will be installed in node_modules. See yarn website for more info.

Webpack

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.

Webpack configuration files are in the tools directory. If you need to edit them, check Webpack website for more information.

F# source files

The template only contains two F# source files: the project (.fsproj) and a source file (.fs) in src folder.

Where to go from here

Check more Fable samples, use another template like Fable.Template.Elmish.React or SAFE.Template, and check the awesome-fable for a curated list of resources provided by the community.