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/manual/v12.0.0/build-configuration.mdx
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,24 @@ Note that the path resolution for the command (`node` in this case) is done so:
116
116
117
117
The command itself is called from inside `lib/bs`.
118
118
119
+
## jsx
120
+
121
+
Controls how the compiler emits JSX and which runtime (if any) it delegates to. A minimal configuration looks like this:
122
+
123
+
```json
124
+
{
125
+
"jsx": {
126
+
"version": 4
127
+
}
128
+
}
129
+
```
130
+
131
+
-`version`: JSX transform version. `4` enables the React 17+ transform and is the current and only supported option in v12.
132
+
-`module`: Override the target module that receives JSX calls. Useful for [generic JSX transforms](./jsx#generic-jsx-transform-jsx-beyond-react-experimental); omit it when using the built-in React runtime.
133
+
-`preserve`: When `true`, the compiler re-emits JSX syntax in the generated JavaScript so bundlers or other tooling can take over the transform later. The regenerated JSX might differ slightly from the original source but stays semantically equivalent. See [Preserve mode](./jsx#preserve-mode) for details.
134
+
135
+
All fields are optional; unspecified fields fall back to the defaults mentioned above. Combine them as needed for your project's JSX runtime.
136
+
119
137
## package-specs
120
138
121
139
Output to either CommonJS (the default) or JavaScript module. Example:
**Note** again that this isn't the transform for ReScriptReact; ReScriptReact turns the final list into an array. But the idea still applies.
153
164
154
-
So naturally, `<MyComponent> myChild </MyComponent>` is transformed to `MyComponent.createElement(~children=list{myChild}, ())`. I.e. whatever you do, the arguments passed to the children position will be wrapped in a list.
165
+
So naturally, `<MyComponent> myChild </MyComponent>` is transformed to `React.jsx(MyComponent.make, {children: myChild})`. I.e. whatever you do, the arguments passed to the children position will be wrapped in a list.
155
166
156
167
## Usage
157
168
@@ -173,8 +184,12 @@ Here's a JSX tag that shows most of the features.
@@ -205,7 +220,9 @@ JSX props spread is supported now, but in a stricter way than in JS.
205
220
```
206
221
207
222
```js
208
-
React.createElement(Comp, {
223
+
import*asJsxRuntimefrom"react/jsx-runtime";
224
+
225
+
JsxRuntime.jsx(Comp.make, {
209
226
a:"a",
210
227
b:"b",
211
228
});
@@ -246,9 +263,11 @@ JSX supports punning. `<input checked />` is just a shorthand for `<input checke
246
263
```
247
264
248
265
```js
249
-
React.createElement(MyComponent, {
250
-
isLoading:true,
266
+
import*asJsxRuntimefrom"react/jsx-runtime";
267
+
268
+
JsxRuntime.jsx(MyComponent, {
251
269
text: text,
270
+
isLoading:true,
252
271
onClick: onClick,
253
272
});
254
273
```
@@ -276,7 +295,9 @@ such props in your custom `JsxDOM.domProps` type ([see generic JSX transform](#g
276
295
```
277
296
278
297
```js
279
-
React.createElement("model-viewer", {
298
+
import*asJsxRuntimefrom"react/jsx-runtime";
299
+
300
+
JsxRuntime.jsx("model-viewer", {
280
301
"touch-actions":"pan-y",
281
302
src: src,
282
303
});
@@ -437,3 +458,37 @@ To enable this, you need to configure the `jsx` `module` in your `rescript.json`
437
458
```
438
459
439
460
_value "Preact" is the name of the module that implements the generic JSX transform._
461
+
462
+
## Preserve mode
463
+
464
+
**Since 12.0**
465
+
466
+
JSX Preserve Mode keeps JSX syntax in the compiled JavaScript output instead of transforming it to `JsxRuntime.jsx` calls. This lets bundlers (ESBuild, SWC, Next.js) or React Server Components handle JSX transformation.
467
+
468
+
### Configuration
469
+
470
+
```json
471
+
{
472
+
"jsx": {
473
+
"version": 4,
474
+
"preserve": true
475
+
}
476
+
}
477
+
```
478
+
479
+
<CodeTablabels={["ReScript", "JS Output"]}>
480
+
481
+
```res
482
+
let c1 = <div className="foo"> {React.string("Hello")} </div>
483
+
let c2 = <MyComponent text="hey" isLoading=true onClick />
484
+
```
485
+
486
+
```js
487
+
let c1 =<div className={"foo"}>{"Hello"}</div>;
488
+
489
+
let c2 =<MyComponent.make text={"hey"} isLoading={true} onClick={onClick} />;
490
+
```
491
+
492
+
</CodeTab>
493
+
494
+
Note that the JSX output is functional but not always the most aesthetically pleasing.
0 commit comments