.jsx and .tsx files out of the box. Bun’s internal transpiler converts JSX syntax into vanilla JavaScript before execution.
react.tsx
Configuration
Bun reads yourtsconfig.json or jsconfig.json configuration files to determines how to perform the JSX transform internally. To avoid using either of these, the following options can also be defined in bunfig.toml.
The following compiler options are respected.
jsx
How JSX constructs are transformed into vanilla JavaScript internally. The table below lists the possible values of jsx, along with their transpilation of the following simple JSX component:
jsxFactory
Note — Only applicable when
jsx is react."createElement". This is useful for libraries like Preact that use a different function name ("h").
jsxFragmentFactory
Note — Only applicable when
jsx is react.<>Hello</>; only applicable when jsx is react. Default value is "Fragment".
jsxImportSource
Note — Only applicable when
jsx is react-jsx or react-jsxdev.createElement, jsx, jsxDEV, etc) will be imported. Default value is "react". This will typically be necessary when using a component library like Preact.
JSX pragma
All of these values can be set on a per-file basis using pragmas. A pragma is a special 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. This is a shorthand syntax useful for assigning a variable to a prop with the same name.react.tsx