diff --git a/examples/with-emotion-vanilla/.babelrc b/examples/with-emotion-vanilla/.babelrc new file mode 100644 index 0000000000..d69237b388 --- /dev/null +++ b/examples/with-emotion-vanilla/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": [["next/babel"]], + "plugins": ["@emotion/babel-plugin"] +} diff --git a/examples/with-emotion-vanilla/.gitignore b/examples/with-emotion-vanilla/.gitignore new file mode 100644 index 0000000000..1437c53f70 --- /dev/null +++ b/examples/with-emotion-vanilla/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel diff --git a/examples/with-emotion-vanilla/README.md b/examples/with-emotion-vanilla/README.md new file mode 100644 index 0000000000..f43e633dfc --- /dev/null +++ b/examples/with-emotion-vanilla/README.md @@ -0,0 +1,24 @@ +# Emotion Vanilla Example + +Extract and inline critical css with +[emotion](https://github.com/emotion-js/emotion/tree/master/packages/emotion), +[@emotion/server](https://github.com/emotion-js/emotion/tree/master/packages/server), +[@emotion/css](https://github.com/emotion-js/emotion/tree/master/packages/css) + +## Deploy your own + +Deploy the example using [Vercel](https://vercel.com): + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-emotion-vanilla) + +## How to use + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: + +```bash +npx create-next-app --example with-emotion-vanilla with-emotion-vanilla-app +# or +yarn create next-app --example with-emotion-vanilla with-emotion-vanilla-app +``` + +Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). diff --git a/examples/with-emotion-vanilla/package.json b/examples/with-emotion-vanilla/package.json new file mode 100644 index 0000000000..4d271b1761 --- /dev/null +++ b/examples/with-emotion-vanilla/package.json @@ -0,0 +1,20 @@ +{ + "name": "with-emotion-vanilla", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start" + }, + "license": "MIT", + "devDependencies": { + "@emotion/babel-plugin": "11.0.0" + }, + "dependencies": { + "@emotion/css": "11.0.0", + "@emotion/server": "11.0.0", + "next": "latest", + "react": "^17.0.1", + "react-dom": "^17.0.1" + } +} diff --git a/examples/with-emotion-vanilla/pages/_document.js b/examples/with-emotion-vanilla/pages/_document.js new file mode 100644 index 0000000000..e347250677 --- /dev/null +++ b/examples/with-emotion-vanilla/pages/_document.js @@ -0,0 +1,34 @@ +import Document, { Html, Head, Main, NextScript } from 'next/document' +import * as React from 'react' +import { renderStatic } from '../shared/renderer' +export default class AppDocument extends Document { + static async getInitialProps(ctx) { + const page = await ctx.renderPage() + const { css, ids } = await renderStatic(page.html) + const initialProps = await Document.getInitialProps(ctx) + return { + ...initialProps, + styles: ( + + {initialProps.styles} +