Skip to content

Commit 9a594bd

Browse files
oneknuckleheadgatsbybotLekoArts
authoredApr 1, 2022
chore(babel-preset-gatsby): Updated README to include babel presets (#35069)
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com> Co-authored-by: Lennart <lekoarts@gmail.com>
1 parent 69642db commit 9a594bd

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed
 

‎docs/docs/reference/config-files/gatsby-config.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ See more about [adding develop middleware](/docs/api-proxy/#advanced-proxying).
370370

371371
## jsxRuntime
372372

373-
Setting to "automatic" allows the use of JSX without having to import React. More information can be found on the [Introducing the new JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) blog post.
373+
Setting to `automatic` allows the use of JSX without having to import React. More information can be found on the [Introducing the new JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) blog post.
374374

375375
```javascript:title=gatsby-config.js
376376
module.exports = {
@@ -380,10 +380,13 @@ module.exports = {
380380

381381
## jsxImportSource
382382

383-
With the new jsxRuntime you can set which package React should use as underlying jsx transformer. For example you can set it to "@emotion/react" so by default @emotion/react is used instead of the react package.
383+
When `jsxRuntime` is set you can choose which package React should use as underlying JSX transformer with `jsxImportSource`. For example you can set it to `@emotion/react` so by default `@emotion/react` is used instead of the `react` package.
384384

385385
```javascript:title=gatsby-config.js
386386
module.exports = {
387+
jsxRuntime: "automatic",
387388
jsxImportSource: "@emotion/react",
388389
}
389390
```
391+
392+
**Please note:** For now you'll also need to set this configuration inside `babel-preset-gatsby`, see [its jsxImportSource documentation](https://github.com/gatsbyjs/gatsby/blob/master/packages/babel-preset-gatsby/README.md#reactImportSource).

‎packages/babel-preset-gatsby/README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,28 @@ npm install --dev babel-preset-gatsby
3737

3838
`{ [string]: number | string }`, defaults to `{ "browsers": ["last 4 versions", "safari >= 7", "ie >= 9"] }` in production and `{ "browsers": ["last 2 versions", "not ie <= 11", "not android 4.4.3"] }` in development when targeting the browser and `{ "node": 6 }` in production and `{ "node": "current" }` in development when targeting Node.js.
3939

40-
Use this option to configure [custom target browsers](https://www.gatsbyjs.com/docs/babel/).
40+
Use this option to configure [custom target browsers](https://www.gatsbyjs.com/docs/how-to/custom-configuration/babel/).
41+
42+
### `reactRuntime`
43+
44+
`'classic' | 'automatic'`, defaults to `'classic'`. Allows the use of JSX without having to import React (learn more in the [official blog post](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)). If you only want to set the runtime to `automatic` without a custom JSX transformer, you can use the [`gatsby-config` option](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/#jsxruntime).
45+
46+
### `reactImportSource`
47+
48+
`string`, defaults to `null`. Set which package React should use as underlying JSX transformer. For example you can set it to `@emotion/react` so by default `@emotion/react` is used instead of the react package. In order to use `reactImportSource` you must set `reactRuntime` to automatic.
49+
50+
Example:
51+
52+
```json
53+
{
54+
"presets": [
55+
[
56+
"babel-preset-gatsby",
57+
{
58+
"reactRuntime": "automatic",
59+
"reactImportSource": "@emotion/react"
60+
}
61+
]
62+
]
63+
}
64+
```

0 commit comments

Comments
 (0)
Please sign in to comment.