Docs / Language Manual / Installation


Prerequisite: NPM, which comes with NodeJS. Yarn also works.

To install ReScript globally:

npm install -g bs-platform

New Project

git clone cd rescript-project-template npm install npm run build node src/

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 rescript-react 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

npm install --save-dev bs-platform

Create config file

Create a bsconfig.json file in the root of your project with the following content.

{ "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.

"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 rescript-react. Here's the quick version:

npm install @rescript/react --save

Make the following changes to your bsconfig.json file:

"reason": { "react-jsx": 3 }, "bs-dependencies": ["@rescript/react"],

Integration with the Existing 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.