Installation
Prerequisite: NPM, which comes with NodeJS. Yarn also works.
To install ReScript globally:
SHnpm install -g bs-platform
New Project
SHgit clone https://github.com/rescript-lang/rescript-project-template
cd rescript-project-template
npm install
npm run build
node src/Demo.bs.js
That compiles your ReScript into JavaScript, then uses NodeJS to run said JavaScript. We recommend you use our highly unique workflow of keeping a tab open for the generated .bs.js
file, so that you can learn how ReScript transforms to JavaScript. Not many languages output clean JavaScript code you can manually inspect!
During development, instead of running npm run build
each time to compile, use npm run start
to start a watcher that recompiles automatically after file changes.
Alternatively, to start a ReasonReact app, follow the instructions here.
Integrate Into Existing JS Project
You can install ReScript locally into an existing JavaScript project using the following steps.
Install ReScript
SHnpm install --save-dev bs-platform
Create config file
Create a bsconfig.json
file in the root of your project with the following content.
JSON{
"name": "your-project-name",
"bsc-flags": ["-bs-super-errors"],
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".bs.js",
"namespace": true,
"bs-dependencies": [],
"ppx-flags": [],
"refmt": 3
}
Update
sources
to indicate where your ReScript source files will be located.
See Build Configuration for more details on bsconfig.json
.
Add scripts to package.json
You may also like to add two scripts to your package.json
to help with compiling ReScript.
JSON"scripts": { "re:build": "bsb -make-world -clean-world", "re:watch": "bsb -make-world -clean-world -w" }
Enabling React JS
If you would like to enable React in your ReScript code, use the following additional steps:
Install Reason React.
SHnpm install reason-react
Make the following changes to your bsconfig.json
file:
JSON"reason": { "react-jsx": 3 }, "bs-dependencies": ["reason-react"],
Using the compiled code
Since ReScript compiles to clean readable JS files the rest of your existing toolchain (e.g. Babel and Webpack) should just work.
See the Export to JS guide to learn how to import ReScript compiled modules into your existing project.
See the Converting from JS guide to learn how to convert existing JS code to ReScript.