Skip to content

Commit cdbae05

Browse files
committed
feat: allow to specify JSX Runtime for @babel/preset-react`
1 parent 8dc88d0 commit cdbae05

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

docs/pages/build.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ yarn add --dev react-native-builder-bob
139139

140140
> Note: If you enable Codegen generated code shipping, React Native won't build the scaffold code automatically when you build your test app. You need to rebuild the codegen scaffold code manually each time you make changes to your spec. If you want to automate this process, you can create a new project with `create-react-native-library` and inspect the example app.
141141
142-
##### Opting out of Codegen shipping __(not recommended)__
142+
##### Opting out of Codegen shipping **(not recommended)**
143143

144144
If you have a reason to not ship Codegen generated scaffold code with your library, you need to remove the [codegen target](#codegen) and add `package.json` to your `exports` field. Otherwise, React Native Codegen will skip spec generation for your library when your library is consumed as an NPM library. You can find the related issue [here](https://github.com/callstack/react-native-builder-bob/issues/637).
145145

@@ -238,6 +238,10 @@ Example:
238238
["module", { "esm": true, "sourceMaps": false }]
239239
```
240240

241+
##### `jsxRuntime`
242+
243+
Explicitly set your [runtime](https://babeljs.io/docs/babel-preset-react#runtime). Defaults to `automatic`.
244+
241245
#### `typescript`
242246

243247
Enable generating type definitions with `tsc` if your source code is written in [TypeScript](http://www.typescriptlang.org/).

packages/react-native-builder-bob/babel-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function (api, options, cwd) {
3737
[
3838
require.resolve('@babel/preset-react'),
3939
{
40-
runtime: 'automatic',
40+
runtime: options.jsxRuntime || 'automatic',
4141
},
4242
],
4343
require.resolve('@babel/preset-typescript'),

packages/react-native-builder-bob/src/utils/compile.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Options = Input & {
1313
copyFlow?: boolean;
1414
modules: 'commonjs' | 'preserve';
1515
exclude: string;
16+
jsxRuntime?: 'automatic' | 'classic';
1617
};
1718

1819
const sourceExt = /\.([cm])?[jt]sx?$/;
@@ -29,6 +30,7 @@ export default async function compile({
2930
copyFlow,
3031
sourceMaps = true,
3132
report,
33+
jsxRuntime = 'automatic',
3234
}: Options) {
3335
const files = glob.sync('**/*', {
3436
cwd: source,
@@ -113,6 +115,7 @@ export default async function compile({
113115
// If a file is explicitly marked as ESM, then preserve the syntax
114116
/\.m[jt]s$/.test(filepath) ? 'preserve' : modules,
115117
esm,
118+
jsxRuntime,
116119
},
117120
],
118121
],

0 commit comments

Comments
 (0)