InfoQ Homepage News Transcompiling F# to Javascript with Fable
Transcompiling F# to Javascript with Fable
This item in japanese
Aug 22, 2016 1 min read
Write for InfoQ
Feed your curiosity. Help 550k+ globalsenior developers
each month stay ahead.Get in touch
Fable is a F# to Javascript transpiler. It can compile an F# script or a whole F# project to Javascript. Fable is executed through a command line interface, giving the option to either compile an .fsx script or a whole project. It is distributed as an npm package.
Fable supports most of the F# core library and a bit of .NET BCL. All basic types are supported fully or with some specific exceptions. One notable exception is async. The async computation expression works as expected, minus RunSynchronously which is not available.
Fable can be extended through user created plugins. Fable plugins are usually used to replace calls to external libraries during the compilation process. Creating a plugin is done by implementing the IReplacePlugin interface and its single method TryReplace. The following shows the skeleton of a plugin to replace System.Random:
type RandomPlugin() =
interface IReplacePlugin with
member x.TryReplace com (info: Fable.ApplyInfo) =
match info.ownerFullName with
| "System.Random" ->
match info.methodName with
| ".ctor" -> failwith "TODO"
| "Next" -> failwith "TODO"
| _ -> None
| _ -> None
Plugins can be used to handle more complex scenarios, such as translating test frameworks. NUnit is currently supported through a plugin translating tests to Mocha.
Mobile apps can also be created with Fable through the use of React Native. React Native makes it possible to compile React applications to Android and iOS apps. A Fable plugin provides the bindings to React Native. It must be noted that the mobile app support through React Native is an experimental feature, subject to frequent changes.
Fable is an open source project available on GitHub. Documentation and code samples can be found on Fable's website. For an example of usage in a full-fledged project, Ionide, a plugin for F# editing in VsCode and Atom, is powered by Fable since its 2.0 release.
-
Related Editorial
-
Related Sponsors
-
Popular across InfoQ
-
Anthropic Lead: HTML Increasingly Better Than Markdown at Keeping Humans Engaged in Agentic Loops
-
AWS Launches Blocks, an Open-Source TypeScript Framework Designed for AI Agents to Build Backends
-
Google OpenRL is an Experimental Self-hosted API for LLM Post-Training Fine-Tuning
-
AWS Introduces Workload Credentials Provider for Automated Certificate and Secret Management
-
AI Is Moving up the Software Lifecycle: from Code Review to PRD Governance
-
Architectural Patterns: Moving Beyond Cloud-Native to Local-First - Insights from Adam Wiggins
-
The InfoQ Newsletter
A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example
