@babel/preset-react
This preset always includes the following plugins:
- @babel/plugin-syntax-jsx
- @babel/plugin-transform-react-jsx
- @babel/plugin-transform-react-display-name
And with the development
option:
Classic runtime adds:
Automatic runtime (since v7.9.0
) adds the functionality for these plugins automatically when the development
option is enabled. If you have automatic runtime enabled, adding @babel/plugin-transform-react-jsx-self or @babel/plugin-transform-react-jsx-source will error.
Note: Flow syntax support is no longer enabled in v7. For that, you will need to add the Flow preset.
Installation
You can also check out the React Getting Started page
- npm
- Yarn
- pnpm
npm install --save-dev @babel/preset-react
yarn add --dev @babel/preset-react
pnpm add --save-dev @babel/preset-react
Usage
With a configuration file (Recommended)
Without options:
babel.config.json
{
"presets": ["@babel/preset-react"]
}
With options:
babel.config.json
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "automatic", // defaults to automatic
"importSource": "custom-jsx-library", // defaults to react(only in automatic runtime)
"throwIfNamespace": false // defaults to true
// "pragma": "dom", // default pragma is React.createElement (only in classic runtime)
// "pragmaFrag": "DomFrag", // default is React.Fragment (only in classic runtime)
}
]
]
}