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
  • X
  • BlueSky
  • GitHub
  • Forum
Language Manual
Overview
  • Introduction
  • Installation
  • 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
    • Configuration
  • Pinned Dependencies
  • Interop with JS Build Systems
  • Performance
Guides
  • Converting from JS
Extra
  • Newcomer Examples
  • Project Structure
  • FAQ
Docs / Language Manual / External Stdlib
Edit

External Stdlib

Since 9.0

Your ReScript project depends on the bs-platform (soon rescript) package as a devDependency, which includes our compiler, build system and runtime like Belt. However, you had to move it to dependency in package.json if you publish your code:

  • To Docker or other low-storage deployment devices.

  • For pure JS/TS consumers who probably won't install bs-platform in their own project.

In these cases, the size or mere presence of bs-platform can be troublesome, since it includes not just our necessary runtime like Belt, but also our compiler and build system.

To solve that, we now publish our runtime as a standalone package at @rescript/std, whose versions mirror bs-platform's. Now you can keep bs-platform as a devDependency and have only @rescript/std as your runtime dependency.

This is an advanced feature. Please only use it in the aforementioned scenarios. If you already use a JS bundler with dead code elimination, you might not need this feature.

Configuration

Say you want to publish a JS-only ReScript 9.0 library. Install the packages like this:

SH
npm install bs-platform@9.0.0 --save-dev npm install @rescript/std@9.0.0 --save

Then add this to bsconfig.json:

JSON
{ // ... "external-stdlib" : "@rescript/std" }

Now the compiled JS code will import using the path defined by external-stdlib. Check the JS output tab:

ReScriptJS output
Belt.Array.forEach([1, 2, 3], num => Js.log(num))

Make sure the version number of bs-platform and @rescript/std match in your package.json to avoid running into runtime issues due to mismatching stdlib assumptions.

Configuration SchemaPinned Dependencies

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on