Skip to content

Commit f296a24

Browse files
tjzelsatya164
andauthored
feat: allow to specify JSX Runtime for @babel/preset-react` (#695)
<!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on a single change. --> ### Summary In 0595213 the JSX runtime was changed to `automatic` without the option for the user to opt back in for `classic`. The `classic` runtime is needed for NativeWind library, which is dependent on Reanimated. Fixes - software-mansion/react-native-reanimated#6665 - #678 ### Test plan 🚀 --------- Co-authored-by: Satyajit Sahoo <[email protected]>
1 parent 8dc88d0 commit f296a24

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/pages/build.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const browserslist = require('browserslist');
66
* Babel preset for React Native Builder Bob
77
* @param {'commonjs' | 'preserve'} options.modules - Whether to compile modules to CommonJS or preserve them
88
* @param {Boolean} options.esm - Whether to output ES module compatible code, e.g. by adding extension to import/export statements
9+
* @param {'automatic' | 'classic'} options.jsxRuntime - Which JSX runtime to use, defaults to 'automatic'
910
*/
1011
module.exports = function (api, options, cwd) {
1112
const cjs = options.modules === 'commonjs';
@@ -37,7 +38,8 @@ module.exports = function (api, options, cwd) {
3738
[
3839
require.resolve('@babel/preset-react'),
3940
{
40-
runtime: 'automatic',
41+
runtime:
42+
options.jsxRuntime !== undefined ? options.jsxRuntime : 'automatic',
4143
},
4244
],
4345
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)