Skip to content

Commit 50ea59a

Browse files
ChristopherBiscardiDSchau
authored andcommitted
Emotion update (#10500)
* Move babel-plugin-emotion to v10 Removed legacy version support which also reduces the number of packages that need to be installed for the tutorial, etc. * update tutorial install packages * update global styles tutorial * Update README.md
1 parent c957c43 commit 50ea59a

File tree

9 files changed

+47
-85
lines changed

9 files changed

+47
-85
lines changed

docs/docs/creating-global-styles.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ To start, create a new Gatsby site with the [hello world starter](https://github
7575
```shell
7676
gatsby new global-styles https://github.com/gatsbyjs/gatsby-starter-hello-world
7777
cd global-styles
78-
npm install --save gatsby-plugin-emotion emotion emotion-server react-emotion
78+
npm install --save gatsby-plugin-emotion @emotion/core @emotion/styled
7979
```
8080

8181
Create `gatsby-config.js` and add the Emotion plugin:
@@ -90,21 +90,27 @@ Next, add a layout component at `src/components/layout.js`:
9090

9191
```jsx:title=src/components/layout.js
9292
import React from "react"
93-
import styled, { injectGlobal } from "react-emotion"
94-
95-
injectGlobal`
96-
div {
97-
background: red;
98-
color: white;
99-
}
100-
`
93+
import { Global, css } from "@emotion/core"
94+
import styled from "@emotion/styled"
10195

10296
const Wrapper = styled("div")`
10397
border: 2px solid green;
10498
padding: 10px;
10599
`
106100

107-
export default ({ children }) => <Wrapper>{children}</Wrapper>
101+
export default ({ children }) => (
102+
<Wrapper>
103+
<Global
104+
styles={css`
105+
div {
106+
background: red;
107+
color: white;
108+
}
109+
`}
110+
/>
111+
{children}
112+
</Wrapper>
113+
)
108114
```
109115

110116
Then, update `src/pages/index.js` to use the layout:

docs/tutorial/part-four/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Then install some other needed dependencies at the root of the project. You'll u
9696
"Kirkham", and you'll try out a CSS-in-JS library, ["Emotion"](https://emotion.sh/):
9797

9898
```shell
99-
npm install --save gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion emotion emotion-server @emotion/core
99+
npm install --save gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion @emotion/core
100100
```
101101

102102
Set up a site similar to what you ended with in [Part Three](/tutorial/part-three). This site will have a layout component and two page components:

packages/gatsby-plugin-emotion/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ Provide support for using the css-in-js library
44
[Emotion](https://github.com/emotion-js/emotion) including server side
55
rendering.
66

7+
**This plugin supports Emotion v10+**
8+
9+
Older versions should use versions of this plugin which support Emotion 8 and 9. Check out the Emotion 10 [migration
10+
guide](https://emotion.sh/docs/migrating-to-emotion-10#incremental-migration) for more information on how to upgrade.
11+
712
## Install
813

914
```
10-
npm install --save gatsby-plugin-emotion emotion emotion-server @emotion/core @emotion/styled
15+
npm install --save gatsby-plugin-emotion @emotion/core @emotion/styled
1116
```
1217

1318
## How to use

packages/gatsby-plugin-emotion/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
"url": "https://github.com/gatsbyjs/gatsby/issues"
88
},
99
"dependencies": {
10-
"@babel/plugin-transform-react-jsx": "^7.1.6",
11-
"@babel/runtime": "^7.0.0",
12-
"babel-plugin-emotion": "^10.0.0",
13-
"babel-plugin-jsx-pragmatic": "^1.0.2"
10+
"@emotion/babel-preset-css-prop": "10.0.5",
11+
"@babel/runtime": "^7.0.0"
1412
},
1513
"devDependencies": {
1614
"@babel/cli": "^7.0.0",
@@ -27,9 +25,7 @@
2725
"license": "MIT",
2826
"main": "index.js",
2927
"peerDependencies": {
30-
"@emotion/core": "^10.0.0",
31-
"emotion": "^10.0.0",
32-
"emotion-server": "^10.0.0",
28+
"@emotion/core": "^10.0.5",
3329
"gatsby": ">2.0.0"
3430
},
3531
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-emotion",

packages/gatsby-plugin-emotion/src/gatsby-browser.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/gatsby-plugin-emotion/src/gatsby-node.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
export const onCreateBabelConfig = ({ actions }, pluginOptions) => {
2-
const pragmaName = `___EmotionJSX`
3-
4-
actions.setBabelPlugin({
5-
name: `babel-plugin-jsx-pragmatic`,
2+
actions.setBabelPreset({
3+
name: `@emotion/babel-preset-css-prop`,
64
options: {
7-
export: `jsx`,
8-
module: `@emotion/core`,
9-
import: pragmaName,
10-
},
11-
})
12-
13-
actions.setBabelPlugin({
14-
name: `@babel/plugin-transform-react-jsx`,
15-
options: {
16-
pragma: pragmaName,
17-
pragmaFrag: `React.Fragment`,
18-
},
19-
})
20-
21-
actions.setBabelPlugin({
22-
name: `babel-plugin-emotion`,
23-
options: {
24-
cssPropOptimization: true,
255
sourceMap: process.env.NODE_ENV !== `production`,
266
autoLabel: process.env.NODE_ENV !== `production`,
277
...(pluginOptions ? pluginOptions : {}),

packages/gatsby-plugin-emotion/src/gatsby-ssr.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/gatsby-plugin-emotion/src/wrap-element.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

yarn.lock

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,16 @@
10691069
follow-redirects "^1.2.5"
10701070
is-buffer "^1.1.5"
10711071

1072+
"@emotion/[email protected]":
1073+
version "10.0.5"
1074+
resolved "https://registry.yarnpkg.com/@emotion/babel-preset-css-prop/-/babel-preset-css-prop-10.0.5.tgz#955485c6f621247ee35dc1e6bd8fef0ba1d3286f"
1075+
integrity sha512-Mf1651pWaqraE2jJdX1/+ArCBLhubxNoNrs0mfYOriIRxwnmjoKQLIEYTMNl/K7ZkIu2PNwvLKGv74fo3wYovA==
1076+
dependencies:
1077+
"@babel/plugin-transform-react-jsx" "^7.1.6"
1078+
babel-plugin-emotion "^10.0.5"
1079+
babel-plugin-jsx-pragmatic "^1.0.2"
1080+
object-assign "^4.1.1"
1081+
10721082
"@emotion/[email protected]":
10731083
version "0.7.1"
10741084
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.7.1.tgz#9833722341379fb7d67f06a4b00ab3c37913da53"
@@ -1079,10 +1089,10 @@
10791089
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.1.tgz#e93c13942592cf5ef01aa8297444dc192beee52f"
10801090
integrity sha512-Qv4LTqO11jepd5Qmlp3M1YEjBumoTHcHFdgPTQ+sFlIL5myi/7xu/POwP7IRu6odBdmLXdtIs1D6TuW6kbwbbg==
10811091

1082-
"@emotion/[email protected].0":
1083-
version "0.11.0"
1084-
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.0.tgz#9332b483a112af7b515d20470a7bf1aa5f8dcf6c"
1085-
integrity sha512-SpUumzuN7CxEGvJKe3bul8+VKdcNleACokv5YgS+k4KQIurdq7dbm4sM7aT9hBx3ccMpDfg5BYVfR3NPoeU5PA==
1092+
"@emotion/serialize@^0.11.3":
1093+
version "0.11.3"
1094+
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.3.tgz#c4af2d96e3ddb9a749b7b567daa7556bcae45af2"
1095+
integrity sha512-6Q+XH/7kMdHwtylwZvdkOVMydaGZ989axQ56NF7urTR7eiDMLGun//pFUy31ha6QR4C6JB+KJVhZ3AEAJm9Z1g==
10861096
dependencies:
10871097
"@emotion/hash" "0.7.1"
10881098
"@emotion/memoize" "0.7.1"
@@ -2972,15 +2982,15 @@ babel-plugin-dynamic-import-node@^1.2.0:
29722982
dependencies:
29732983
babel-plugin-syntax-dynamic-import "^6.18.0"
29742984

2975-
babel-plugin-emotion@^10.0.0:
2976-
version "10.0.0"
2977-
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.0.tgz#ceb177a64d5ccba3c28d7de4a0697d0f3a66315f"
2978-
integrity sha512-O0ykSwaJQVHuZcAd0/TuMbG6QzuArGheL9XeEoQfgBeFlcyrGEj/2JexsCk4iMMiykxW7hfulm0zKy864PWOSw==
2985+
babel-plugin-emotion@^10.0.5:
2986+
version "10.0.5"
2987+
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.5.tgz#05ec47cde94f984b0b2aebdd41f81876cf9cbb24"
2988+
integrity sha512-ezct2vKACg4juSV0/A/4QIDJu2+5Sjna/8rX/LXY8D0qG8YEP3fu8pe5FqZ9yFGa8WOJ1sivf3/QKM/5C8naIg==
29792989
dependencies:
29802990
"@babel/helper-module-imports" "^7.0.0"
29812991
"@emotion/hash" "0.7.1"
29822992
"@emotion/memoize" "0.7.1"
2983-
"@emotion/serialize" "0.11.0"
2993+
"@emotion/serialize" "^0.11.3"
29842994
babel-plugin-macros "^2.0.0"
29852995
babel-plugin-syntax-jsx "^6.18.0"
29862996
convert-source-map "^1.5.0"

0 commit comments

Comments
 (0)