Skip to content

Commit 0163f10

Browse files
committed
Update external stdlib docs
1 parent 64ea2c8 commit 0163f10

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pages/docs/manual/latest/build-external-stdlib.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ canonical: "/docs/manual/latest/build-external-stdlib"
1111

1212
In a typical ReScript application, you'd ship a package with an npm dependency to `bs-platform` (`rescript`), which means downloading several tens of megabytes of executables.
1313

14-
Whenever a ReScript developer wants to publish a package just for pure JS consumption / lean container deployment, they would be required to use a bundler to bundle up their library / stdlib code, which is not ideal.
14+
Whenever you'd want to publish a package just for pure JS consumption / lean container deployment (package MB sizes), you'd be required to use a bundler to bundle up all the required stdlib runtime modules with your package source, which is not ideal.
1515

16-
To fix this problem, you can just depend on our pre-compiled stdlib JS files, published as a separate npm package called [`@rescript/std`](https://www.npmjs.com/package/@rescript/std). Each new ReScript release has a matching `@rescript/std` release for runtime compatibility.
16+
To fix this problem, you can configure your ReScript project to use our external stdlib package ([`@rescript/std`](https://www.npmjs.com/package/@rescript/std)) and make `bs-platform` a dev-only dependency.
17+
18+
Every ReScript package release has a matching `@rescript/std` release for runtime compatibility.
19+
20+
**Important:** To prevent unnecessary complications, only use this feature when...
21+
- You want to ship a library for JS / TS consumers without making them depend on `bs-platform`
22+
- You can't depend on `bs-platform` due to toolchain size (docker containers, low-storage deployment devices, etc)
1723

1824
## Configuration
1925

20-
For example, let's assume we want to build a JS package that is built on ReScript 9.0. We'd first install our `@rescript/std` package:
26+
For example, let's assume we want to build a JS-only package that is built with ReScript 9.0. First, we would set up our dependencies like this:
2127

2228
```
2329
npm install [email protected] --save-dev
2430
npm install @rescript/[email protected] --save
2531
```
2632

27-
In your `bsconfig.json`, set up following configuration:
33+
In our `bsconfig.json`, we set up the following configuration:
2834

2935
```json
3036
{
@@ -33,7 +39,7 @@ In your `bsconfig.json`, set up following configuration:
3339
}
3440
```
3541

36-
With this configuration set, compiled JS code will now point to the defined external-stdlib path:
42+
Now our compiled JS code will point to the defined external-stdlib path (check the JS output of the following code snippet):
3743

3844
<CodeTab labels={["ReScript", "JavaScript"]}>
3945

@@ -42,7 +48,7 @@ Belt.Array.forEach([1, 2, 3], (num) => Js.log(num))
4248
```
4349

4450
```js
45-
// Note the import path starting with "@rescript/std"
51+
// Note the import path starting with "@rescript/std".
4652
import * as Belt_Array from "@rescript/std/lib/es6/belt_Array.js";
4753

4854
Belt_Array.forEach([
@@ -57,10 +63,5 @@ Belt_Array.forEach([
5763

5864
</CodeTab>
5965

60-
The JavaScript output above was compiled with an `es6` target, but will also work with `commonjs`.
66+
**Important:** When using the `external-stdlib` configuration, always make sure the version numbers of `bs-platform` and `@rescript/std` match in your `package.json` file. Otherwise you might run into runtime problems due to mismatching stdlib behavior.
6167

62-
**Important:** When using this option, you need to make sure that the version number of `bs-platform` and `@rescript/std` matches with the same version number in your `package.json` file, otherwise you'll eventually run into runtime problems due to mismatching stdlib behavior!
63-
64-
To prevent unnecessary complications, only use this feature when...
65-
- You want to ship a library for JS / TS consumers without making them depend on `bs-platform`
66-
- You can't depend on `bs-platform` due to toolchain size (docker containers, low-storage deployment devices, etc)

0 commit comments

Comments
 (0)