You are currently looking at the v11.0 docs, which are still a work in progress. If you miss anything, you may find it in the older v10.0 docs here.
Installation
Prerequisites
New Project
The fastest and easiest way to spin up a new ReScript project is with the create-rescript-app project generator. You can start it with any of the aforementioned package managers or npx
.
npm create rescript-app
Follow the steps of the setup.
Trigger a ReScript build:
SHnpm run res:build
If you selected the "basic" template, simply run it with:
SHnode src/Demo.res.js
That compiles your ReScript into JavaScript, then uses Node.js to run said JavaScript. We recommend you use our unique workflow of keeping a tab open for the generated .res.js
file, so that you can learn how ReScript transforms into JavaScript. Not many languages output clean JavaScript code you can inspect and learn from!
During development, instead of running npm run res:build
each time to compile, use npm run res:dev
to start a watcher that recompiles automatically after file changes.
Integrate Into an Existing JS Project
If you already have a JavaScript project into which you'd like to add ReScript you can do that in the following ways:
Quick Setup
In the root directory of your project, execute:
npm create rescript-app
create-rescript-app
will tell you that a package.json
file has been detected and ask you if it should install ReScript into your project. Just follow the steps accordingly.
Manual Setup
Install ReScript locally:
npmyarnpnpmbunnpm install rescript
Create a ReScript build configuration file (called
rescript.json
) at the root:JSON{ "name": "your-project-name", "sources": [ { "dir": "src", // update this to wherever you're putting ReScript files "subdirs": true } ], "package-specs": [ { "module": "es6", "in-source": true } ], "suffix": ".res.js", "bs-dependencies": [] }
See Build Configuration for more details on
rescript.json
.Add convenience
npm
scripts topackage.json
:JSON"scripts": { "res:build": "rescript", "res:dev": "rescript build -w" }
Since ReScript compiles to clean readable JS files, the rest of your existing toolchain (e.g. Babel and Webpack) should just work!
Helpful guides:
Integrate with a ReactJS Project
To start a rescript-react app, or to integrate ReScript into an existing ReactJS app, follow the instructions here.