.jsx and .tsx files. Bun’s internal transpiler converts JSX syntax into vanilla JavaScript before execution.
react.tsx
Configuration
Bun reads yourtsconfig.json or jsconfig.json to determine how to perform the JSX transform internally. If you’d rather not use either, you can set the same options in bunfig.toml.
Bun respects the following compiler options.
jsx
How JSX constructs are transformed into vanilla JavaScript internally. The following table lists the possible values of jsx, along with how each transpiles this JSX component:
jsxFactory
Only applicable when
jsx is react."React.createElement". Set this for libraries like Preact that use a different function name ("h").
jsxFragmentFactory
Only applicable when
jsx is react.<>Hello</>. Default value is "React.Fragment".
jsxImportSource
Only applicable when
jsx is react-jsx or react-jsxdev.createElement, jsx, or jsxDEV) is imported from. Default value is "react". You’ll typically need this when using a component library like Preact.
JSX pragma
You can set any of these values per file with a pragma, a comment that sets a compiler option in a particular file.Logging
Bun implements special logging for JSX to make debugging easier. Given the following file:index.tsx
Prop punning
The Bun runtime also supports “prop punning” for JSX: a shorthand for assigning a variable to a prop with the same name.react.tsx