diff --git a/README.md b/README.md index c2711e132eaff..f043ac2788f8a 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ export default () => (

Examples - +

It's possible to use any existing CSS-in-JS solution. The simplest one is inline styles: diff --git a/examples/with-aphrodite/README.md b/examples/with-aphrodite/README.md new file mode 100644 index 0000000000000..d00a24dcec463 --- /dev/null +++ b/examples/with-aphrodite/README.md @@ -0,0 +1,30 @@ + +# Example app with aphrodite + +## How to use + +Download the example (or clone the repo)[https://github.com/zeit/next.js.git]: + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-aphrodite +cd with-aphrodite +``` + +Install it and run: + +```bash +npm install +npm run dev +``` + +Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) + +```bash +now +``` + +## The idea behind the example + +This example features how yo use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [Aphrodite](https://github.com/Khan/aphrodite/). + +For this purpose we are extending the `` and injecting the server side rendered styles into the ``. diff --git a/examples/with-aphrodite/package.json b/examples/with-aphrodite/package.json new file mode 100644 index 0000000000000..014e97592e303 --- /dev/null +++ b/examples/with-aphrodite/package.json @@ -0,0 +1,15 @@ +{ + "name": "with-aphrodite", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "aphrodite": "^1.1.0", + "next": "^2.0.0-beta" + }, + "author": "", + "license": "ISC" +} diff --git a/examples/with-aphrodite/pages/_document.js b/examples/with-aphrodite/pages/_document.js new file mode 100644 index 0000000000000..a4f6cda2c01b3 --- /dev/null +++ b/examples/with-aphrodite/pages/_document.js @@ -0,0 +1,24 @@ +import Document, { Head, Main, NextScript } from 'next/document' +import { StyleSheetServer } from 'aphrodite' + +export default class MyDocument extends Document { + static async getInitialProps ({ renderPage }) { + const { html, css } = StyleSheetServer.renderStatic(() => renderPage()) + return { ...html, css } + } + + render () { + return ( + + + My page +