Skip to content

Commit

Permalink
feat: allow to specify JSX Runtime for @babel/preset-react` (#695)
Browse files Browse the repository at this point in the history
<!-- 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]>
  • Loading branch information
tjzel and satya164 authored Nov 21, 2024
1 parent 8dc88d0 commit f296a24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/pages/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ Example:
["module", { "esm": true, "sourceMaps": false }]
```

##### `jsxRuntime`

Explicitly set your [runtime](https://babeljs.io/docs/babel-preset-react#runtime). Defaults to `automatic`.

#### `typescript`

Enable generating type definitions with `tsc` if your source code is written in [TypeScript](http://www.typescriptlang.org/).
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native-builder-bob/babel-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const browserslist = require('browserslist');
* Babel preset for React Native Builder Bob
* @param {'commonjs' | 'preserve'} options.modules - Whether to compile modules to CommonJS or preserve them
* @param {Boolean} options.esm - Whether to output ES module compatible code, e.g. by adding extension to import/export statements
* @param {'automatic' | 'classic'} options.jsxRuntime - Which JSX runtime to use, defaults to 'automatic'
*/
module.exports = function (api, options, cwd) {
const cjs = options.modules === 'commonjs';
Expand Down Expand Up @@ -37,7 +38,8 @@ module.exports = function (api, options, cwd) {
[
require.resolve('@babel/preset-react'),
{
runtime: 'automatic',
runtime:
options.jsxRuntime !== undefined ? options.jsxRuntime : 'automatic',
},
],
require.resolve('@babel/preset-typescript'),
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Options = Input & {
copyFlow?: boolean;
modules: 'commonjs' | 'preserve';
exclude: string;
jsxRuntime?: 'automatic' | 'classic';
};

const sourceExt = /\.([cm])?[jt]sx?$/;
Expand All @@ -29,6 +30,7 @@ export default async function compile({
copyFlow,
sourceMaps = true,
report,
jsxRuntime = 'automatic',
}: Options) {
const files = glob.sync('**/*', {
cwd: source,
Expand Down Expand Up @@ -113,6 +115,7 @@ export default async function compile({
// If a file is explicitly marked as ESM, then preserve the syntax
/\.m[jt]s$/.test(filepath) ? 'preserve' : modules,
esm,
jsxRuntime,
},
],
],
Expand Down

0 comments on commit f296a24

Please sign in to comment.