Page
Library
Module
Module type
Parameter
Class
Class type
Source
Melange is a compiler for producing performant JavaScript from Reason and OCaml. Powered by a strong static type system with best-in-class type inference based on the OCaml compiler, Melange facilitates producing robust JavaScript code.
This project is forked from the ReScript compiler shifting focus to integrating with the OCaml ecosystem. This enables code sharing between backend and frontend using Dune's virtual libraries.
Melange also introduces a ReScript compatibility layer to maintain compatibility with ReScript's Syntax - preserving access to ReScripts ecosystem of packages.
Write in Reason/OCaml, use OCaml libraries or ReScript packages to kickstart your project!
A small write-up with more details on the motivation behind this project can be found in this blog post.
This project is currently unreleased. There are, however, a few ways to try it out.
The easiest way to get started is to clone the basic template and run esy in the project root. To install Esy, npm install -g esy should cover most workflows. If you have NodeJS / npm available, npx esy is even shorter.
You can also install melange with opam:
Pin melange to the version on GitHub:
opam pin melange https://github.com/melange-re/melange.gitYou should now be able to run melange from your switch:
opam exec -- mel --helpMelange also has some runtime dependencies that need to be symlinked into node_modules to be discoverable by bundlers like webpack:
rm -rf node_modules/melange
mkdir -p node_modules/melange
ln -sfn $(opam var prefix)/lib/melange node_modules/melange/lib(adapted from the equivalent step in the esy build for melange-basic-template: https://github.com/melange-re/melange-basic-template/blob/3605fb491d45e74472be58f653482e15e21c9159/esy.json#L15).
Melange has good support for Nix:
nix run github:melange-re/melange -- build runs melange.nix shell github:melange-re/melange -c $SHELL enters a shell with mel and melc in $PATH. Try out mel --help, for example. for available options.github:melange-re/melange as a flake input exports melange as the default packagePlease reach out on the ReasonML Discord if you can't figure it out!
Until Melange has first-class support in Dune, ocaml-lsp support relies on having Melange generate a .merlin file to provide the language server with information about your project.
To enable editor support via ocaml-lsp, add the following to your esy.json:
// esy.json
{
"devDependencies": {
"@opam/ocaml-lsp-server": ">= 1.12.0",
"@opam/dot-merlin-reader": "*"
}
}Then use the --fallback-read-dot-merlin flag when running ocaml-lsp.
If using the VSCode OCaml Platform extension, use the Custom sandbox option and provide the flag to ocaml-lsp via the command template:
// .vscode/settings.json
{
"ocaml.sandbox": {
"kind": "custom",
"template": "esy $prog $args --fallback-read-dot-merlin"
}
}The current Melange distribution works on OCaml 4.14 and OCaml 5.00+trunk. If you need to use Melange with OCaml 4.12 (the only formerly supported version), you can consume the 0.1.0 tag for this repo (make sure to similarly use the 4.12.0+mel tag for melange-compiler-libs).
Name | Purpose | Dependencies | Notes |
|---|---|---|---|
Package manager | Installed with NPM | Obtaining dependencies (e.g. | |
Package manager | None | Obtaining dependencies (e.g. | |
Build tool | Installed with | Well-known OCaml build tool; supports custom rules that can be composed to build anything | |
Syntax | Installed with | a library that implements an alternative syntax to OCaml | |
Compiler that emits Script | Esy (to install), Dune (to build), Reason (used as a library) | Supports OCaml, Reason and ReScript syntaxes; derived from ReScript, focused on compatibility with the wider OCaml ecosystem | |
The brand around a syntax and a compiler that emits JavaScript | None | Distributed via NPM as prebuilt binaries; previously called BuckleScript |
Yes! ReScript syntax is supported, but ReScript won't have as many features as the OCaml or Reason syntaxes due to ReScript being built on top of an old OCaml version (4.06 - Released 2018). (e.g. letop binding operators, generalized module open expressions, or local substitutions in signatures).
refmt flag gone?Upstream removed the refmt flag, which used to allow configuring the path to a custom Reason binary. This was a welcome change for this repo too, so we cherry-picked it. The rationale: this project uses Reason as a library, so you can simply depend on the Reason version that you'd like in the usual way, via your preferred package manager.
See CONTRIBUTING.md.
See also Credits.md concerning some individual components of Melange.
See COPYING and COPYING.LESSER
See Credits for more details.