文档 / Language Manual / Installation
Edit

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

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:start 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 bsconfig.json.

  • Add convenience npm scripts to package.json:

    JSON
    "scripts": { "res:build": "rescript", "res:start": "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.