Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify JSX Runtime for @babel/preset-react` #695

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading