Skip to content

Commit 6da8fa6

Browse files
authored
Merge pull request #194 from kevanstannard/installation-existing-project
Installation in an existing project documentation
2 parents b1a84d5 + 43e664f commit 6da8fa6

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

pages/docs/manual/latest/installation.mdx

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,78 @@ Alternatively, **to start a [ReasonReact](https://reasonml.github.io/reason-reac
3434

3535
## Integrate Into Existing JS Project
3636

37-
You can install the toolchain locally to an existing JS project, through the familiar command:
37+
You can install ReScript locally into an existing JavaScript project using the following steps.
38+
39+
### Install ReScript
3840

3941
```sh
4042
npm install --save-dev bs-platform
4143
```
4244

43-
The rest is the same as above. Since we output clean `.bs.js` files, the rest of your existing toolchain (e.g. Babel and Webpack) should mostly just work. Nothing to learn on the bundling side!
45+
### Create config file
46+
47+
Create a `bsconfig.json` file in the root of your project with the following content.
48+
49+
```json
50+
{
51+
"name": "your-project-name",
52+
"bsc-flags": ["-bs-super-errors"],
53+
"sources": [
54+
{
55+
"dir": "src",
56+
"subdirs": true
57+
}
58+
],
59+
"package-specs": [
60+
{
61+
"module": "es6",
62+
"in-source": true
63+
}
64+
],
65+
"suffix": ".bs.js",
66+
"namespace": true,
67+
"bs-dependencies": [],
68+
"ppx-flags": [],
69+
"refmt": 3
70+
}
71+
```
72+
73+
> 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 [Reason React](https://reasonml.github.io/reason-react/en/).
93+
94+
```sh
95+
npm install reason-react
96+
```
97+
98+
Make the following changes to your `bsconfig.json` file:
99+
100+
```json
101+
"reason": { "react-jsx": 3 },
102+
"bs-dependencies": ["reason-react"],
103+
```
104+
105+
### Using the compiled 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.
44110

45-
See also our highly recommended guide to [convert from JavaScript](converting-from-js).
111+
See the [Converting from JS guide](converting-from-js) to learn how to convert existing JS code to ReScript.

0 commit comments

Comments
 (0)