Docs / Language Manual / Installation
Edit

Installation

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

To install ReScript globally:

SH
npm install -g bs-platform

New Project

SH
git 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 unique workflow of keeping a tab open for the generated .bs.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 build each time to compile, use npm run start to start a watcher that recompiles automatically after file changes.

Integrate Into Existing JS Project

If you already have a JavaScript project into which you'd like to add ReScript:

  • Install ReScript locally as a devDependency:

    SH
    npm install --save-dev bs-platform

  • Create a ReScript build configuration 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": ".bs.js", "bs-dependencies": [] }
    See Build Configuration for more details on bsconfig.json.

  • Add convenience npm scripts to package.json:

    JSON
    "scripts": { "re:build": "bsb -make-world -clean-world", "re:start": "bsb -make-world -clean-world -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.