Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 2.2 KB

build-external-stdlib.mdx

File metadata and controls

59 lines (41 loc) · 2.2 KB
titlemetaTitledescriptioncanonical
External Stdlib
External Stdlib
Configuring an external ReScript stdlib package
/docs/manual/latest/build-external-stdlib

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:

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

Then add this to bsconfig.json:

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

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

<CodeTab labels={["ReScript", "JS output"]}>

Belt.Array.forEach([1, 2, 3], num=>Js.log(num))
// Note the require path starting with "@rescript/std".varBelt_Array=require("@rescript/std/lib/js/belt_Array.js");Belt_Array.forEach([1,2,3],function(num){console.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.

close