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
That compiles your ReScript into JavaScript, then uses NodeJS to run said JavaScript. **We recommend you use our unique workflow of keeping a tab open for the generated `.bs.js` file**, so that you can learn how ReScript transforms into JavaScript. Not many languages output clean JavaScript code you can inspect and learn from!
30
28
31
29
During development, instead of running `npm run build` each time to compile, use `npm run start` to start a watcher that recompiles automatically after file changes.
> Update `sources` to indicate where your ReScript source files will be located.
74
-
75
-
See [Build Configuration](build-configuration) for more details on `bsconfig.json`.
76
-
77
-
### Add scripts to package.json
78
-
79
-
You may also like to add two scripts to your `package.json` to help with compiling ReScript.
80
-
81
-
```json
82
-
"scripts": {
83
-
"re:build": "bsb -make-world -clean-world",
84
-
"re:watch": "bsb -make-world -clean-world -w"
85
-
}
86
-
```
87
-
88
-
### Enabling React JS
89
-
90
-
If you would like to enable React in your ReScript code, use the following additional steps:
91
-
92
-
Install [rescript-react](/docs/react/latest/introduction). Here's the quick version:
93
-
94
-
```sh
95
-
npm install @rescript/react --save
96
-
```
97
-
98
-
Make the following changes to your `bsconfig.json` file:
99
-
100
-
```json
101
-
"reason": { "react-jsx": 3 },
102
-
"bs-dependencies": ["@rescript/react"],
103
-
```
104
-
105
-
### Integration with the Existing Code
106
-
107
-
Since ReScript compiles to clean readable JS files the rest of your existing toolchain (e.g. Babel and Webpack) should just work.
108
-
109
-
See the [Export to JS guide](import-from-export-to-js#export-to-javascript) to learn how to import ReScript compiled modules into your existing project.
110
-
111
-
See the [Converting from JS guide](converting-from-js) to learn how to convert existing JS code to ReScript.
33
+
If you already have a JavaScript project into which you'd like to add ReScript:
34
+
35
+
- Install ReScript locally as a [devDependency](https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file):
36
+
```sh
37
+
npm install --save-dev bs-platform
38
+
```
39
+
- Create a ReScript build configuration at the root:
40
+
```json
41
+
{
42
+
"name": "your-project-name",
43
+
"sources": [
44
+
{
45
+
"dir": "src", // update this to wherever you're putting ReScript files
46
+
"subdirs": true
47
+
}
48
+
],
49
+
"package-specs": [
50
+
{
51
+
"module": "es6",
52
+
"in-source": true
53
+
}
54
+
],
55
+
"suffix": ".bs.js",
56
+
"bs-dependencies": []
57
+
}
58
+
```
59
+
See [Build Configuration](build-configuration) for more details on `bsconfig.json`.
60
+
- Add convenience `npm` scripts to `package.json`:
61
+
```json
62
+
"scripts": {
63
+
"re:build": "bsb -make-world -clean-world",
64
+
"re:start": "bsb -make-world -clean-world -w"
65
+
}
66
+
```
67
+
68
+
Since ReScript compiles to clean readable JS files, the rest of your existing toolchain (e.g. Babel and Webpack) should just work!
69
+
70
+
Helpful guides:
71
+
-[Converting from JS](converting-from-js).
72
+
-[Shared Data Types](shared-data-types).
73
+
-[Import from/Export to JS](import-from-export-to-js).
74
+
75
+
### Integrate with a ReactJS Project
76
+
77
+
To start a [rescript-react](/docs/react/latest/introduction) app, or to integrate ReScript into an existing ReactJS app, follow the instructions [here](/docs/react/latest/installation).
0 commit comments