-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #765 from davesnx/source
- Loading branch information
Showing
24 changed files
with
828 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Js_of_ocaml | ||
--- | ||
|
||
[Js_of_ocaml](https://ocsigen.org/js_of_ocaml/3.7.0/manual/overview) | ||
|
||
## Template | ||
|
||
To get started check out this [`hello-jsoo-esy`](https://github.com/jchavarri/hello-jsoo-esy) template: | ||
|
||
``` | ||
git clone https://github.com/jchavarri/hello-jsoo-esy.git | ||
cd hello-jsoo-esy | ||
esy | ||
npm install | ||
npm run webpack | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
title: Melange | ||
--- | ||
|
||
One of the best usages of Reason is to compile it to JavaScript an run it in the browser or any JavaScript platform such as [Node.js](https://nodejs.org), [Deno](https://deno.com), [Cloudflare Workers](https://workers.cloudflare.com). | ||
|
||
Reason compiles to JavaScript thanks to our partner project, [Melange](https://melange.re). | ||
|
||
## What's Melange? | ||
|
||
[Melange](https://melange.re) is a backend for the OCaml compiler that emits readable, modular and highly performant JavaScript code. | ||
|
||
> Melange strives to provide the best integration with both the OCaml and JavaScript ecosystems | ||
If you have experience with JavaScript and the ecosystem we recommend Melange, over other alternatives such as [Js_of_ocaml](compiling-to-js-with-jsoo.md). | ||
|
||
## Getting started | ||
|
||
The install guide on the Melange website shares a lot of common steps with [our installation](installation.md), check it out: [melange.re/v2.0.0/getting-started](https://melange.re/v2.0.0/getting-started). | ||
|
||
Since [Melange v1](https://buttondown.email/anmonteiro/archive/melange-hits-v10/), Melange integrates with dune. This means that you can use dune to compile your Reason code to JavaScript and also to bytecode or native. | ||
|
||
## Template | ||
|
||
To get started with Reason and Melange, there's an official template: | ||
|
||
```bash | ||
git clone https://github.com/melange-re/melange-opam-template | ||
cd melange-opam-template | ||
|
||
# Create opam switch and install dependencies | ||
make init | ||
|
||
# In separate terminals: | ||
|
||
make watch # Watch for reason file changes and recompile | ||
make serve # Run the development server | ||
``` | ||
|
||
## Manual | ||
|
||
If you prefer to do all the steps manually, here is a step by step. Assuming you have an opam switch with OCaml 5.1.0. If not, check the [installation](installation.md#setup-a-new-environment-manually) guide. | ||
|
||
#### Install melange | ||
|
||
```bash | ||
opam install melange | ||
``` | ||
|
||
#### Create dune-project | ||
|
||
If you don't have a `dune-project` file, create one with the following content: | ||
|
||
```lisp | ||
; dune-project | ||
(dune lang 3.8) | ||
(use melange 0.1) ; Here we enable melange to work with dune | ||
``` | ||
|
||
#### Emit JavaScript | ||
|
||
In your `dune` file, add a `melange.emit` stanza to emit JavaScript. | ||
|
||
The `melange.emit` stanza tells dune to generate JavaScript files from a set of libraries and modules. In-depth documentation about this stanza can be found in the [build-system on the Melange documentation](https://melange.re/v2.0.0/build-system/#entry-points-with-melangeemit). | ||
|
||
```lisp | ||
; dune | ||
(melange.emit | ||
(target app)) | ||
``` | ||
|
||
#### Libraries | ||
|
||
dune allows to define libraries by creating a dune file inside a folder and adding a library stanza: https://dune.readthedocs.io/en/stable/concepts/package-spec.html#libraries | ||
|
||
To compile a library with melange, add the `(modes melange)` stanza to the library dune file. | ||
|
||
```diff | ||
(library | ||
(name ui_library) | ||
+ (modes melange) | ||
) | ||
``` | ||
|
||
Once you have a melange library, you can add it to the `melange.emit` stanza: | ||
```lisp | ||
; dune | ||
(melange.emit | ||
(target app) | ||
(libraries ui_library)) | ||
``` | ||
|
||
#### Compile | ||
|
||
Each time you compile the project, dune will emit JavaScript files under `_build/default/app/` (`app` comes from the `(target app)` defined under `melange.emit`). | ||
|
||
To compile the project, run: | ||
|
||
```bash | ||
dune build # Compile the entire project | ||
# or compile the melange alias (only melange.emit stanzas) | ||
dune build @melange | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Getting started | ||
--- | ||
|
||
This section of the docs is all about quickly setting up a Reason development enviromanet up and running. | ||
|
||
## Get an overview of Reason | ||
|
||
```reason | ||
type schoolPerson = | ||
| Teacher | ||
| Director | ||
| Student(string); | ||
let greeting = person => | ||
switch (person) { | ||
| Teacher => "Hey Professor!" | ||
| Director => "Hello Director." | ||
| Student("Richard") => "Still here Ricky?" | ||
| Student(anyOtherName) => "Hey, " ++ anyOtherName ++ "." | ||
}; | ||
module Intro = { | ||
[@react.component] | ||
let make = (~person) => { | ||
<p> {React.string(greeting(person))} </p> | ||
} | ||
}; | ||
``` | ||
> This snippet includes [@react.component] which comes from [reason-react](https://reasonml.github.io/reason-react/) | ||
For an introduction to most language features check out the [overview](overview.md) | ||
|
||
## Try Reason in your browser | ||
|
||
To start immediately an online REPL is available at [Sketch.sh](https://sketch.sh) | ||
or open the [playground](playground) | ||
|
||
## Install Reason | ||
|
||
Install Reason on your computer to start writing Reason applications. | ||
Check the [installation](installation.md) for a more detailed guide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: Installation via esy | ||
--- | ||
|
||
This page is a detailed explanation on how to install Reason with [esy](https://esy.sh/) Easy package management for native Reason, OCaml and more, both manually and using a template. | ||
|
||
Reason can be installed with a package manager like [opam](https://opam.ocaml.org/) also, check the [installation page](installation.md) for more details. | ||
|
||
### Requirements | ||
|
||
System Requirements: | ||
|
||
- Node.js 16.14 or later. | ||
- macOS, Windows (including WSL), and Linux are supported. | ||
|
||
Esy is distributed via npm, install it using the following command: | ||
|
||
``` | ||
npm install -g esy | ||
``` | ||
> It's recommended to install esy globally | ||
### Automatic | ||
Using the [`hello-reason`](https://github.com/esy-ocaml/hello-reason) template | ||
|
||
### Manual installation | ||
|
||
To add packages that happen to be hosted on npm, run `esy add npm-package-name`. | ||
|
||
To add packages from opam's registry, prefix the package name with `@opam`. `esy` treats the npm scope `@opam` specially. In this case, `esy` will install any package name with the `@opam` scope directly from [opam](https://opam.ocaml.org/packages/). | ||
|
||
```bash | ||
esy add @opam/bos | ||
``` | ||
|
||
<!-- Add a warning about being crazy slow the first time --> | ||
|
||
We install reason from opam using the following command: | ||
|
||
``` | ||
esy add @opam/reason | ||
``` | ||
|
||
Link to getting started with esy https://esy.sh/docs/en/getting-started.html | ||
See the [configuration](https://esy.sh/docs/en/configuration.html) section from the complete `esy` docs. | ||
|
||
To create your first Reason native CLI program, run the following commands: | ||
|
||
``` | ||
git clone https://github.com/esy-ocaml/hello-reason.git | ||
cd hello-reason | ||
# Install all dependencies (might take a while in the first run) | ||
esy | ||
# Compile and run Hello.exe | ||
esy x Hello | ||
``` | ||
|
||
## What's Next? | ||
|
||
After you have successfully compiled your first example, it's time to [set up your editor](editor-plugins.md) to get access to all the nice features such as auto-completion. Later on you can check out the [language basics](overview.md) to get a basic understanding of all the Reason language constructs. |
Oops, something went wrong.