Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/TheAngryByrd/Fable.Template.Library

F# Template for create and publishing Fable Libraries
https://github.com/TheAngryByrd/Fable.Template.Library

dotnet-core dotnet-template fable fable-libraries fsharp javascript

Last synced: about 1 month ago
JSON representation

F# Template for create and publishing Fable Libraries

Awesome Lists containing this project

README

        

# Fable.Template.Library
F# Template for create and publishing [Fable](https://github.com/fable-compiler/Fable) Libraries

## Getting started

### Grab the template from nuget:

```
dotnet new -i "Fable.Template.Library::*"
```

### Use the new template:

```
dotnet new fable-library -n CoolFableLibrary
cd CoolFableLibrary
./build.sh
```

## Builds

MacOS/Linux | Windows
:---: | :---:
[![Travis Badge](https://travis-ci.org/TheAngryByrd/Fable.Template.Library.svg?branch=master)](https://travis-ci.org/TheAngryByrd/Fable.Template.Library) | [![Build status](https://ci.appveyor.com/api/projects/status/github/TheAngryByrd/Fable.Template.Library?svg=true)](https://ci.appveyor.com/project/TheAngryByrd/fable-template-library)
[![Build History](https://buildstats.info/travisci/chart/TheAngryByrd/Fable.Template.Library)](https://travis-ci.org/TheAngryByrd/Fable.Template.Library/builds) | [![Build History](https://buildstats.info/appveyor/chart/TheAngryByrd/fable-template-library)](https://ci.appveyor.com/project/TheAngryByrd/fable-template-library)

## Nuget

Stable | Prerelease
:---: | :---:
[![NuGet Badge](https://buildstats.info/nuget/Fable.Template.Library)](https://www.nuget.org/packages/Fable.Template.Library/) | [![NuGet Badge](https://buildstats.info/nuget/Fable.Template.Library?includePreReleases=true)](https://www.nuget.org/packages/Fable.Template.Library/)

## Building

Make sure the following **requirements** are installed in your system:

* [dotnet SDK](https://www.microsoft.com/net/download/core) 2.0 or higher
* [node.js](https://nodejs.org) 6.11 or higher
* [yarn](https://yarnpkg.com)
* [Mono](http://www.mono-project.com/) if you're on Linux or macOS.

Then you just need to type `./build.cmd` or `./build.sh`

## A note about Fable Libraries vs Fable Bindings

There are two kinds of Fable packages:

- **JS Bindings**: These don't contain any actual code, only signatures and attributes normally generated by [ts2fable](https://www.npmjs.com/package/ts2fable). They're just used to provide a type-safe to interact with a JS library from Fable.
- **Libraries**: These contain F# code that will be compiled to JS by Fable when being referenced by a consumer project.

The distinction is important because Fable can read metadata from .dll assemblies (like signatures and attributes) but not executable code, for that it needs the **F# sources**. For JS bindings _without actual code_ you don't need to worry as they can be distributed as any other Nuget package. However, Fable libraries need a couple of extra steps:

- First, the package must contain a folder named **fable** with the F# sources (and if necessary other files like JS scripts).
- The `fable` folder must contain an **.fsproj file with the same name as the Nuget package**.

This is not difficult to do and usually only requires adding a tag to your project file ([example](https://github.com/fable-compiler/fable-react-native/blob/6a7cc0e5074b985ef94e49a631cb8285eb9950c8/src/Fable.React.Native.fsproj#L32-L34)), but you need to make sure all the sources get into the package with the proper directory structure. Also, take into account Fable will just make a simple XML parsing to extract the source files from the .fsproj, so you should avoid MSBuild conditionals, etc.

Because Fable will compile your sources you must be careful with compiler directives too (like `#if MY_SYMBOL`, etc). Though you can use this to your advantage and do some logging in debug mode (`#if DEBUG`). And remember also that Fable will always define the `FABLE_COMPILER` symbol when compiling to JS.