Docs / Language Manual / Installation
Edit

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

SH
git clone https://github.com/rescript-lang/rescript-project-template cd rescript-project-template npm install npm run res:build node src/Demo.bs.js

or use the create-rescript-app tool:

SH
npm create rescript-app // Select basic template cd <your-rescript-project-name> npm run res:build node src/Demo.bs.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 .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 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:

  • Install ReScript locally:

    SH
    npm install rescript

  • 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 rescript.json.

  • Add convenience npm scripts to package.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.