If you are switching between languages make sure to delete the fable_modules
folder before invoking Fable again.
Start a new project
This guide you will show you how to create a Fable project from an F# project.
Create a new directory for your project and navigate to it.
mkdir my-fable-project cd my-fable-project
Create a new F# project.
dotnet new console -lang F#
You should now have 2 files:
Program.fs
: the entry point of your appmy-fable-project.fsproj
: the project file which lists your F# code files and libraries
Install Fable tool so we can invoke it from the command line.
dotnet new tool-manifest dotnet tool install fable
Add Fable.Core to your project.
dotnet add package Fable.Core
We can now call Fable to transpile our F# code to the desired target.
# If you want to transpile to JavaScript dotnet fable # If you want to transpile to TypeScript dotnet fable --lang typescript # If you want to transpile to Python dotnet fable --lang python
You should now see a file
Program.fs.<ext>
where<ext>
is the target language extension. For example, if you transpiled to JavaScript, you should see aProgram.fs.js
file.You can now use this file as you would use any other native file in your project.
To go further look into the respective target documentation to have an example of how to use the generated file: