Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Language Manual
Overview
  • Introduction
  • Installation
    • New Project
    • Integrate Into Existing JS Project
  • Editor Plugins
  • Migrate to ReScript Syntax
  • Try
Language Features
  • Overview
  • Let Binding
  • Type
  • Primitive Types
  • Tuple
  • Record
  • Object
  • Variant
  • Polymorphic Variant
  • Null, Undefined and Option
  • Array & List
  • Function
  • If-Else & Loops
  • Pipe
  • Pattern Matching / Destructuring
  • Mutation
  • JSX
  • Exception
  • Lazy Value
  • Async & Promise
  • Module
  • Import & Export
  • Attribute (Decorator)
  • Unboxed
  • Reserved Keyword
JavaScript Interop
  • Interop Cheatsheet
  • Embed Raw JavaScript
  • Shared Data Types
  • External (Bind to Any JS Library)
  • Bind to JS Object
  • Bind to JS Function
  • Import from / Export to JS
  • Bind to Global JS Values
  • JSON
  • Inlining Constants
  • Use Illegal Identifier Names
  • Generate Converters & Helpers
  • Browser Support & Polyfills
  • Libraries & Publishing
Build System
  • Overview
  • Configuration
  • Configuration Schema
  • External Stdlib
  • Pinned Dependencies
  • Interop with JS Build Systems
  • Performance
Guides
  • Converting from JS
Extra
  • Newcomer Examples
  • Project Structure
  • FAQ
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:

  • Converting from JS.

  • Shared Data Types.

  • Import from/Export to JS.

Integrate with a ReactJS Project

To start a rescript-react app, or to integrate ReScript into an existing ReactJS app, follow the instructions here.

IntroductionEditor Plugins

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on