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
Copy file name to clipboardExpand all lines: pages/docs/gentype/latest/getting-started.mdx
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,13 +39,12 @@ For running `gentype` with ReScript via `npm` workflow, add following script in
39
39
40
40
```
41
41
scripts: {
42
-
"build": "bsb -make-world",
43
-
"clean": "bsb -clean-world"
42
+
"build": "rescript",
43
+
"clean": "rescript clean"
44
44
}
45
45
```
46
46
47
-
> **Note:**`bsb` will automatically
48
-
> detect your installed `genType` version.
47
+
> **Note:**`rescript` will automatically detect your installed `genType` version.
49
48
50
49
## Configuration
51
50
@@ -84,7 +83,7 @@ Configure your shim files within `"gentypeconfig"` in your [`bsconfig.json`](htt
84
83
85
84
Open any relevant `*.res` file and add `@genType` annotations to any bindings / values / functions to be used from JavaScript. If an annotated value uses a type, the type must be annotated too. See e.g. [Hooks.res](https://github.com/reason-association/genType/blob/master/examples/typescript-react-example/src/Hooks.res).
86
85
87
-
Save the file and rebuild the project via `npm run bs:build` or similar. You should now see a `*.gen.tsx` (for TypeScript, or `*.gen.js` for Flow) file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
86
+
Save the file and rebuild the project via `npm run bs:build` or similar. You should now see a `*.gen.tsx` (for TypeScript, or `*.gen.js` for Flow) file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
88
87
89
88
Any values exported from `MyComponent.res` can then be imported from JS. For example:
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/build-configuration.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,7 +178,7 @@ The warning number are shown in the build output when they're triggered. The com
178
178
179
179
## bsc-flags
180
180
181
-
Extra flags to pass to the underlying `bsc` call. Notably: `["-bs-super-errors"]` for turning on cleaner error output. No need to pass this flag for a new ReScript project; it's enabled by default.
181
+
Extra flags to pass to the compiler. For advanced usages.
182
182
183
183
## Environment Variables
184
184
@@ -192,4 +192,4 @@ When `NINJA_ANSI_FORCED` is set to `1`: `rescript` produces color.
192
192
When `NINJA_ANSI_FORCED` is set to `0`: `rescript` doesn't produce color.
193
193
When `NINJA_ANSI_FORCED` is not set: `rescript` might or might not produce color, depending on a smart detection of where it's outputted.
194
194
195
-
> Note that bsc, the barebone compiler, will always be passed `-color always`. See more details in [this issue](https://github.com/rescript-lang/rescript-compiler/issues/2984#issuecomment-410669163).
195
+
> Note that the underlying compiler will always be passed `-color always`. See more details in [this issue](https://github.com/rescript-lang/rescript-compiler/issues/2984#issuecomment-410669163).
ReScript comes with a build system, bsb, that's meant to be fast, lean and used as the authoritative build system of the community.
10
+
ReScript comes with a build system, [`rescript`](https://www.npmjs.com/package/rescript), that's fast, lean and used as the authoritative build system of the community.
11
11
12
-
The build description file is called `bsconfig.json`. Every ReScript project needs one.
12
+
Every ReScript project needs a build description file, `bsconfig.json`.
13
13
14
-
## Build Project
14
+
## Options
15
+
16
+
See `rescript -help`:
17
+
18
+
```
19
+
❯ rescript -help
20
+
Available flags
21
+
-v, -version display version number
22
+
-h, -help display help
23
+
Subcommands:
24
+
build
25
+
clean
26
+
format
27
+
convert
28
+
help
29
+
Run rescript subcommand -h for more details,
30
+
For example:
31
+
rescript build -h
32
+
rescript format -h
33
+
The default `rescript` is equivalent to `rescript build` subcommand
34
+
```
35
+
36
+
## Build Project
15
37
16
38
Each build will create build artifacts from your project's source files.
17
39
18
40
**To build a project (including its dependencies / pinned-dependencies)**, run:
19
41
20
42
```sh
21
-
bsb -make-world
43
+
rescript
22
44
```
23
45
24
-
Add `-w` to keep the built-in watcher running. Any new file change will be picked up and the build will re-run.
46
+
Which is an alias for `rescript build`.
25
47
26
-
**Note**: third-party libraries (in `node_modules`, or via `pinned-dependencies`) aren't watched, as doing so may exceed the node.js watcher count limit.
48
+
To keep a build watcher, run:
27
49
28
-
**Note 2**: In case you want to set up a project in a JS-monorepo-esque approach (`yarn workspaces` / `lerna`) where changes in your sub packages should be noticed by the compiler (`bsb -make-world`), you will need to define pinned dependencies in your main project's `bsconfig.json`. More details [here](./build-pinned-dependencies).
50
+
```sh
51
+
rescript build -w
52
+
```
29
53
30
-
**To build only your project's files (without dependencies)**, run:
54
+
Any new file change will be picked up and the build will re-run.
31
55
56
+
**Note**: third-party libraries (in `node_modules`, or via `pinned-dependencies`) aren't watched, as doing so may exceed the node.js watcher count limit.
32
57
33
-
```sh
34
-
bsb
35
-
```
58
+
**Note 2**: In case you want to set up a project in a JS-monorepo-esque approach (`npm` and `yarn` workspaces) where changes in your sub packages should be noticed by the build, you will need to define pinned dependencies in your main project's `bsconfig.json`. More details [here](./build-pinned-dependencies).
36
59
37
60
## Clean Project
38
61
39
62
If you ever get into a stale build for edge-case reasons, use:
40
63
41
64
```sh
42
-
bsb -clean-world
65
+
rescript clean
43
66
```
44
67
45
-
This will clean all your project's build artifacts, including those in your dependencies. Alternatively you can run `bsb -clean` to clean your project's build artifacts only.
68
+
This will clean your own project's build artifacts. To also clean the dependencies' artifacts:
46
69
47
-
For more infos, run `bsb -help` to see all the available options.
ReScript considers performance at install time, build time and run time as a serious feature. Here are some more info, and tips on keeping the build fast. **Feel free to skip this section** if you're just starting out.
10
+
ReScript considers performance at install time, build time and run time as a serious feature; it's one of those things you don't notice until you realize it's missing.
11
11
12
12
## Profile Your Build
13
13
@@ -25,62 +25,58 @@ import Image from "src/components/Image";
25
25
26
26
## Under the Hood
27
27
28
-
ReScript itself uses a build system under the hood, called [Ninja](https://ninja-build.org). Ninja is like Make, but cross-platform, minimal, focuses in perf and destined to be more of a low-level building block than a full-blown build system. In this regard, Ninja's a great implementation detail for bsb.
28
+
ReScript itself uses a build system under the hood, called [Ninja](https://ninja-build.org). Ninja is like Make, but cross-platform, minimal, focuses in perf and destined to be more of a low-level building block than a full-blown build system. In this regard, Ninja's a great implementation detail for `rescript`.
29
29
30
-
ReScript reads into `bsconfig.json` and generates the Ninja build file in `lib/bs`. The file contains the low-level `bsc`-related commands, namespacing rules, intermediate artifacts generation & others. It then runs `ninja` for the actual build.
30
+
ReScript reads into `bsconfig.json` and generates the Ninja build file in `lib/bs`. The file contains the low-level compiler commands, namespacing rules, intermediate artifacts generation & others. It then runs `ninja` for the actual build.
31
31
32
32
## The JS Wrapper
33
33
34
-
`bsb` itself is a Node.js wrapper which takes care of some miscellaneous tasks, plus the watcher. The lower-level, watcher-less, true `bsb` is called `bsb.exe`. It can be located in the same directory as where `bsb` is found:
34
+
`rescript` itself is a Node.js wrapper which takes care of some miscellaneous tasks, plus the watcher. The lower-level, watcher-less, fast native `rescript` is called `rescript.exe`. It's located at `node_modules/rescript/{your-platform}/rescript.exe`.
35
35
36
-
```sh
37
-
> bsb -where
38
-
/usr/local/lib/node_modules/bs-platform/lib
39
-
```
40
-
41
-
The path varies across systems.
42
-
43
-
If you don't need the watcher, you can run said `bsb.exe`: `/usr/local/lib/node_modules/bs-platform/lib/bsb.exe`. This side-steps the node.js startup time, which can be big (in the order of `100ms`).
36
+
If you don't need the watcher, you can run said `rescript.exe`. This side-steps Node.js' long startup time, which can be in the order of `100ms`. Our editor plugin finds and uses this native `rescript.exe` for better performance.
44
37
45
38
## Numbers
46
39
47
-
Raw `bsb.exe` build on a small project should be around `70ms`. This doubles when you use the more common `bsb` wrapper which comes with a watcher, which is practically faster since you don't manually run the build at every change (though you should opt for the raw `bsb.exe` for programmatic usage, e.g. inserting bsb into your existing JS build pipeline).
40
+
Raw `rescript.exe` build on a small project should be around `70ms`. This doubles when you use the JS `rescript` wrapper which comes with a watcher, which is practically faster since you don't manually run the build at every change (though you should opt for the raw `rescript.exe` for programmatic usage, e.g. inserting rescript into your existing JS build pipeline).
48
41
49
42
No-op build (when no file's changed) should be around `15ms`. Incremental rebuild (described soon) of a single file in a project is around `70ms` too.
50
43
51
44
Cleaning the artifacts should be instantaneous.
52
45
53
46
### Extreme Test
54
47
55
-
We've stress-tested bsb on a big project of 10,000 files (2 directories, 5000 files each, first 5000 no dependencies, last 5000 10 dependencies on files from the former directory) using https://github.com/ocaml-omake/omake/blob/perf-test/performance/generate.ml, on Retina Macbook Pro Early 2015 (3.1 GHz Intel Core i7).
48
+
We've stress-tested `rescript.exe` on a big project of 10,000 files (2 directories, 5000 files each, first 5000 no dependencies, last 5000 10 dependencies on files from the former directory) using https://github.com/rescript-lang/build-benchmark, on a Retina Macbook Pro Early 2015 (3.1 GHz Intel Core i7).
Usually we'd recommend to use ReScript in a single-codebase style by using one `bsconfig.json` file for your whole codebase.
13
13
14
-
There are scenarios where you still want to connect and build multiple independent ReScript packages for one main project though (`yarn workspaces`-like "monorepos"). This is where `pinned-dependencies` come into play.
15
-
14
+
There are scenarios where you still want to connect and build multiple independent ReScript packages for one main project though (`npm` workspaces-like "monorepos"). This is where `pinned-dependencies` come into play.
16
15
17
16
## Package Types
18
17
@@ -22,7 +21,7 @@ Before we go into detail, let's first explain all the different package types re
22
21
- Pinned dependencies (these are your local packages that should always rebuild when you build your toplevel, those should be listed in `bs-dependencies` and `pinned-dependencies`)
23
22
- Normal dependencies (these are packages that are consumed from npm and listed via `bs-dependencies`)
24
23
25
-
Whenever a package is being built (`bsb -make-world`), the build system will build the toplevel package with its pinned-dependencies. So any changes made in a pinned dependency will automatically be reflected in the final app.
24
+
Whenever a package is being built (`rescript build`), the build system will build the toplevel package with its pinned-dependencies. So any changes made in a pinned dependency will automatically be reflected in the final app.
26
25
27
26
## Build System Package Rules
28
27
@@ -108,7 +107,6 @@ Our `app` folder would be our toplevel package, consuming our `common` and `mypl
108
107
}
109
108
```
110
109
111
-
Now, whenever we are running `npx bsb -make-world` within our `app` package, the compiler would always rebuild any changes within its pinned dependencies as well.
112
-
113
-
**Important:** ReScript will not rebuild any `pinned-dependencies` in watch mode! This is due to the complexity of file watching, so you'd need to set up your own file-watcher process that runs `bsb -make-world` on specific file changes. E.g. you could use [`watchman-make`](https://facebook.github.io/watchman/docs/watchman-make.html) to automatically run the build task when a file in `common` or `myplugin` has been changed.
110
+
Now, whenever we are running `rescript build` within our `app` package, the compiler would always rebuild any changes within its pinned dependencies as well.
114
111
112
+
**Important:** ReScript will not rebuild any `pinned-dependencies` in watch mode! This is due to the complexity of file watching, so you'd need to set up your own file-watcher process that runs `rescript build` on specific file changes.
Format the code: `./node_modules/.bin/bsc -format src/Main.res`.
156
+
Format the code: `./node_modules/.bin/rescript format src/Main.res`.
157
157
158
158
We have a type error: "The record field student can't be found". That's fine! **Always ensure your code is syntactically valid first**. Fixing type errors comes later.
0 commit comments