Skip to content

Commit ddd3f27

Browse files
authored
Tweak external stdlib page (rescript-lang#296)
Compressed it to 80% and added some new precisions.
1 parent d05b9d3 commit ddd3f27

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,51 @@ canonical: "/docs/manual/latest/build-external-stdlib"
99

1010
**Since 9.0**
1111

12-
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.
12+
Your ReScript project depends on the `bs-platform` (soon `rescript`) package as a [`devDependency`](https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file), 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:
13+
- To Docker or other low-storage deployment devices.
14+
- For pure JS/TS consumers who probably won't install `bs-platform` in their own project.
1315

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.
16+
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.
1517

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.
18+
To solve that, we now publish our runtime as a standalone package at [`@rescript/std`](https://www.npmjs.com/package/@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`.
1719

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)
20+
**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.
2321

2422
## Configuration
2523

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:
24+
Say you want to publish a JS-only ReScript 9.0 library. Install the packages like this:
2725

28-
```
26+
```sh
2927
npm install [email protected] --save-dev
3028
npm install @rescript/[email protected] --save
3129
```
3230

33-
In our `bsconfig.json`, we set up the following configuration:
31+
Then add this to `bsconfig.json`:
3432

3533
```json
3634
{
37-
/* ... */
35+
// ...
3836
"external-stdlib" : "@rescript/std"
3937
}
4038
```
4139

42-
Now our compiled JS code will point to the defined external-stdlib path (check the JS output of the following code snippet):
40+
Now the compiled JS code will import using the path defined by `external-stdlib`. Check the JS output tab:
4341

44-
<CodeTab labels={["ReScript", "JavaScript"]}>
42+
<CodeTab labels={["ReScript", "JS output"]}>
4543

4644
```res
47-
Belt.Array.forEach([1, 2, 3], (num) => Js.log(num))
45+
Belt.Array.forEach([1, 2, 3], num => Js.log(num))
4846
```
4947

5048
```js
51-
// Note the import path starting with "@rescript/std".
52-
import * as Belt_Array from "@rescript/std/lib/es6/belt_Array.js";
53-
54-
Belt_Array.forEach([
55-
1,
56-
2,
57-
3
58-
], (function (num) {
59-
console.log(num);
60-
61-
}));
49+
// Note the require path starting with "@rescript/std".
50+
var Belt_Array = require("@rescript/std/lib/js/belt_Array.js");
51+
52+
Belt_Array.forEach([1, 2, 3], function (num) {
53+
console.log(num);
54+
});
6255
```
6356

6457
</CodeTab>
6558

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.
67-
59+
**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.

0 commit comments

Comments
 (0)