Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 61e3556

Browse files
committed
add emotion support
1 parent 8efb33c commit 61e3556

File tree

6 files changed

+355
-20
lines changed

6 files changed

+355
-20
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["next/babel"]
2+
"presets": ["next/babel", "@emotion/babel-preset-css-prop"]
33
}

README.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1+
This is an opinonated Next.js starter project that makes it relatively simple to spin up a new project.
22

33
## Getting Started
44

55
First, run the development server:
66

77
```bash
8-
npm run dev
9-
# or
108
yarn dev
119
```
1210

11+
If you'd like serverless function support:
12+
13+
```bash
14+
vercel dev
15+
```
16+
17+
I'm personally in the "just do Next.js the Vercel way because it gives me modern best practices without a lot of friction" but if you've got other preferences you probably know how to manage them anyway.
18+
1319
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
1420

15-
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
21+
You can start editing the page by modifying `src/pages/index.js`. The page auto-updates as you edit the file.
22+
23+
You can also add mdx files in `src/pages/` and they will be presented at the cooresponding route.
24+
25+
Tailwind and
1626

1727
## Learn More
1828

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
"test": "jest --watch"
1111
},
1212
"dependencies": {
13+
"@emotion/babel-preset-css-prop": "^10.2.1",
14+
"@emotion/core": "^10.1.1",
15+
"@emotion/styled": "^10.0.27",
1316
"@next/mdx": "^10.0.1",
1417
"dotenv-flow": "^3.2.0",
18+
"emotion": "^10.0.27",
19+
"emotion-server": "^10.0.27",
1520
"husky": "^4.3.0",
1621
"lint-staged": "^10.5.1",
1722
"mdx-prism": "^0.3.1",
@@ -31,7 +36,7 @@
3136
"@babel/plugin-transform-react-jsx": "^7.12.5",
3237
"@tailwindcss/typography": "^0.2.0",
3338
"@testing-library/jest-dom": "^5.11.5",
34-
"@testing-library/react": "^11.11.1",
39+
"@testing-library/react": "^11.1.1",
3540
"@types/node": "^14.14.7",
3641
"@types/react": "^16.9.56",
3742
"babel-jest": "^26.6.3",

src/pages/_document.tsx

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from 'react'
2+
import Document, {
3+
Html,
4+
Head,
5+
Main,
6+
NextScript,
7+
DocumentContext,
8+
} from 'next/document'
9+
import {extractCritical} from 'emotion-server'
10+
11+
export default class MyDocument extends Document {
12+
static async getInitialProps(ctx: DocumentContext) {
13+
const initialProps = await Document.getInitialProps(ctx)
14+
const styles = extractCritical(initialProps.html)
15+
return {
16+
...initialProps,
17+
styles: (
18+
<>
19+
{initialProps.styles}
20+
<style
21+
data-emotion-css={styles.ids.join(' ')}
22+
dangerouslySetInnerHTML={{__html: styles.css}}
23+
/>
24+
</>
25+
),
26+
}
27+
}
28+
29+
render() {
30+
return (
31+
<Html>
32+
<Head>
33+
<link
34+
rel="icon"
35+
href="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/271/cloud-with-lightning-and-rain_26c8-fe0f.png"
36+
/>
37+
</Head>
38+
<body>
39+
<Main />
40+
<NextScript />
41+
</body>
42+
</Html>
43+
)
44+
}
45+
}

src/pages/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {jsx} from '@emotion/core'
12
import Head from 'next/head'
23

34
export default function Home() {
@@ -8,7 +9,9 @@ export default function Home() {
89
<link rel="icon" href="/favicon.ico" />
910
</Head>
1011

11-
<h1 className="text-3xl text-pink-500">Welcome to Your App</h1>
12+
<h1 className="text-3xl text-pink-500" css={{backgroundColor: 'teal'}}>
13+
Welcome to Your App
14+
</h1>
1215
</div>
1316
)
1417
}

0 commit comments

Comments
 (0)