Skip to content

Commit 22cfcf5

Browse files
authored
Merge pull request #1 from zeit/add/css
Added css using aphrodite
2 parents 20e90ed + 7a39dac commit 22cfcf5

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

lib/css.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('aphrodite')

lib/document.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ export default class Document extends Component {
2525
}
2626

2727
export function Head (props, context) {
28-
const { head } = context._documentProps
28+
const { head, css } = context._documentProps
2929
const h = (head || [])
3030
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
31-
return <head>{h}</head>
31+
return <head>
32+
{h}
33+
<style data-aphrodite>{css.content}</style>
34+
</head>
3235
}
3336

3437
Head.contextTypes = { _documentProps: PropTypes.any }

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test": "ava"
1515
},
1616
"dependencies": {
17+
"aphrodite": "0.5.0",
1718
"babel-core": "6.17.0",
1819
"babel-generator": "6.17.0",
1920
"babel-loader": "6.2.5",
@@ -41,6 +42,7 @@
4142
},
4243
"devDependencies": {
4344
"ava": "0.16.0",
45+
"del": "2.2.2",
4446
"gulp": "3.9.1",
4547
"gulp-babel": "6.1.2",
4648
"gulp-cached": "1.1.0",

server/render.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server'
44
import fs from 'mz/fs'
55
import Document from '../lib/document'
66
import App from '../lib/app'
7+
import { StyleSheetServer } from '../lib/css'
78

89
export async function render (path, req, res, { root = process.cwd() } = {}) {
910
const mod = require(resolve(root, '.next', 'pages', path)) || {}
@@ -17,15 +18,20 @@ export async function render (path, req, res, { root = process.cwd() } = {}) {
1718
const bundlePath = resolve(root, '.next', '.next', 'pages', (path || 'index') + '.js')
1819
const component = await fs.readFile(bundlePath, 'utf8')
1920

20-
const app = createElement(App, {
21-
Component,
22-
props,
23-
router: {}
21+
const { html, css } = StyleSheetServer.renderStatic(() => {
22+
const app = createElement(App, {
23+
Component,
24+
props,
25+
router: {}
26+
})
27+
28+
return renderToString(app)
2429
})
2530

2631
const doc = createElement(Document, {
2732
head: [],
28-
html: renderToString(app),
33+
html: html,
34+
css: css,
2935
data: { component },
3036
hotReload: false
3137
})

0 commit comments

Comments
 (0)