To write a library that can be used in Fable you only need to fulfill a few conditions:
- Don't use FSharp.Core/BCL APIs that are not compatible with Fable.
- Keep a simple
.fsprojfile: don't use MSBuild conditions or similar.
- Include the source files in the Nuget package in a folder named
The last point may sound complicated but it's only a matter of adding a couple of lines to your project file and let the
dotnet pack command do all the rest.
<!-- Add source files to "fable" folder in Nuget package --> <ItemGroup> <Content Include="*.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" /> </ItemGroup>
It's a good idea to write unit tests for your library to make sure everything works as expected before publishing. The simplest way for that is to use a JS test runner like Mocha, as in this sample. Or you can also use a library like Fable.Mocha containing more tools for Fable projects.