You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
13
15
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.
15
17
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`.
17
19
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.
23
21
24
22
## Configuration
25
23
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:
// 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
+
});
62
55
```
63
56
64
57
</CodeTab>
65
58
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