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/latest/build-configuration.mdx
+5-4
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ The command itself is called from inside `lib/bs`.
122
122
123
123
## package-specs
124
124
125
-
Output to either CommonJS (the default) or ES6 modules. Example:
125
+
Output to either CommonJS (the default) or JavaScript module. Example:
126
126
127
127
```json
128
128
{
@@ -133,7 +133,8 @@ Output to either CommonJS (the default) or ES6 modules. Example:
133
133
}
134
134
```
135
135
136
-
-`"module": "es6-global"` resolves `node_modules` using relative paths. Good for development-time usage of ES6 in conjunction with browsers like Safari and Firefox that support ES6 modules today. **No more dev-time bundling**!
136
+
-`"module": "commonjs"` generates output as CommonJS format.
137
+
-`"module": "esmodule"` generates output as JavaScript module format. Will be default value in next major.
137
138
-`"in-source": true` generates output alongside source files. If you omit it, it'll generate the artifacts into `lib/js`. The output directory is not configurable otherwise.
138
139
139
140
This configuration only applies to you, when you develop the project. When the project is used as a third-party library, the consumer's own `rescript.json``package-specs` overrides the configuration here, logically.
@@ -198,7 +199,7 @@ To enable genType, set `"gentypeconfig"` at top level in the project's `rescript
198
199
```json
199
200
{
200
201
"gentypeconfig": {
201
-
"module": "es6",
202
+
"module": "esmodule",
202
203
"moduleResolution": "node",
203
204
"generatedFileExtension": ".gen.tsx",
204
205
"debug": {
@@ -211,7 +212,7 @@ To enable genType, set `"gentypeconfig"` at top level in the project's `rescript
211
212
212
213
`generatedFileExtension`: File extension used for genType generated files (defaults to `".gen.tsx"`)
213
214
214
-
`module`: Module format used for the generated `*.gen.tsx` files (supports `"es6"` and `"commonjs"`)
215
+
`module`: Module format used for the generated `*.gen.tsx` files (supports `"esmodule"` and `"commonjs"`)
215
216
216
217
`moduleResolution`: Module resolution strategy used in genType outputs. This may be required for compatibility with TypeScript projects. Specify the value as the same in `tsconfig.json`.
You've seen how ReScript's idiomatic [Import & Export](import-export.md) works. This section describes how we work with importing stuff from JavaScript and exporting stuff for JavaScript consumption.
10
10
11
-
**Note**: due to JS ecosystem's module compatibility issues, our advice of keeping your ReScript file's compiled JS output open in a tab applies here **more than ever**, as you don't want to subtly output the wrong JS module import/export code, on top of having to deal with Babel/Webpack/Jest/Node's CommonJS \<-> ES6 compatibility shims.
11
+
**Note**: due to JS ecosystem's module compatibility issues, our advice of keeping your ReScript file's compiled JS output open in a tab applies here **more than ever**, as you don't want to subtly output the wrong JS module import/export code, on top of having to deal with Babel/Webpack/Jest/Node's CommonJS \<-> JavaScript module compatibility shims.
12
12
13
13
In short: **make sure your bindings below output what you'd have manually written in JS**.
14
14
15
15
## Output Format
16
16
17
17
We support 2 JavaScript import/export formats:
18
18
19
+
- JavaScript module: `import * from 'MyReScriptFile'` and `export let ...`.
19
20
- CommonJS: `require('myFile')` and `module.exports = ...`.
20
-
- ES6 modules: `import * from 'MyReScriptFile'` and `export let ...`.
21
21
22
22
The format is [configurable in via `rescript.json`](build-configuration.md#package-specs).
23
23
@@ -27,19 +27,19 @@ The format is [configurable in via `rescript.json`](build-configuration.md#packa
Depending on whether you're compiling ReScript to CommonJS or ES6 module, **this feature will generate subtly different code**. Please check both output tabs to see the difference. The ES6 output here would be wrong!
77
+
Depending on whether you're compiling ReScript to JavaScript module or CommonJS, **this feature will generate subtly different code**. Please check both output tabs to see the difference. The JavaScript module output here would be wrong!
[Import attributes](https://github.com/tc39/proposal-import-attributes) can be used in ReScript, as long as ReScript is configured to output ES6. You do that by passing configuration to the `@module` attribute:
100
+
[Import attributes](https://github.com/tc39/proposal-import-attributes) can be used in ReScript, as long as ReScript is configured to output JavaScript module. You do that by passing configuration to the `@module` attribute:
The syntax for importing a whole module looks a little different, since we are operating on the module syntax level; instead of using `Js.import`, you may simply `await` the module itself:
As mentioned in ReScript's idiomatic [Import & Export](import-export.md), every let binding and module is exported by default to other ReScript modules (unless you use a `.resi`[interface file](module#signatures)). If you open up the compiled JS file, you'll see that these values can also directly be used by a _JavaScript_ file too.
193
193
194
-
### Export an ES6 Default Value
194
+
### Export a `default` Value
195
195
196
-
If your JS project uses ES6 modules, you're likely exporting & importing some default values:
196
+
If your JS project uses JavaScript module, you're likely exporting & importing some default values:
197
197
198
198
```js
199
199
// student.js
@@ -207,7 +207,7 @@ import studentName from 'student.js';
207
207
208
208
A JavaScript default export is really just syntax sugar for a named export implicitly called `default` (now you know!). So to export a default value from ReScript, you can just do:
// informal transpiler-compatible marker of a default export compiled from ES6
221
+
// informal transpiler-compatible marker of a default export compiled from JavaScript module
222
222
exports.__esModule=true;
223
223
```
224
224
```js
@@ -239,4 +239,4 @@ You can then import this default export as usual on the JS side:
239
239
importstudentNamefrom'ReScriptStudent.js';
240
240
```
241
241
242
-
If your JavaScript's ES6 default import is transpiled by Babel/Webpack/Jest into CommonJS `require`s, we've taken care of that too! See the CommonJS output tab for `__esModule`.
242
+
If your JavaScript's default import is transpiled by Babel/Webpack/Jest into CommonJS `require`s, we've taken care of that too! See the CommonJS output tab for `__esModule`.
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/typescript-integration.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,7 @@ The minimal configuration of genType is following:
132
132
```json
133
133
{
134
134
"gentypeconfig": {
135
-
"module": "es6",
135
+
"module": "esmodule",
136
136
"moduleResolution": "node",
137
137
"generatedFileExtension": ".gen.tsx"
138
138
}
@@ -153,7 +153,7 @@ And don't forget to make sure `allowJs` is set to `true` in the project's `tscon
153
153
154
154
Make sure to set the same `moduleResolution` value in both `rescript.json` and `tsconfig.json`, so that the output of genType is done with the preferred module resolution.
155
155
156
-
For example if the TypeScript project uses ES Modules with `Node16` / `NodeNext` module resolution:
156
+
For example if the TypeScript project uses JavaScript modules with `Node16` / `NodeNext` module resolution:
0 commit comments