Commit 196f71fe authored by Jamie Barton's avatar Jamie Barton Committed by Tim Neutkens

Refactor with tailwindcss example to use next-css (#5461)

Instead of bundling `postcss-cli` we can now make use of `@zeit/with-css`.

This also means we can get rid of the `<style>` import and concurrent build step for css. 🎉 
parent ed2c379f
import NextHead from 'next/head'
import { string } from 'prop-types'
const defaultDescription = ''
const defaultOGURL = ''
const defaultOGImage = ''
const Head = (props) => (
<NextHead>
<meta charset='UTF-8' />
<title>{props.title || ''}</title>
<meta name='description' content={props.description || defaultDescription} />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<link rel='icon' sizes='192x192' href='/static/touch-icon.png' />
<link rel='apple-touch-icon' href='/static/touch-icon.png' />
<link rel='mask-icon' href='/static/favicon-mask.svg' color='#49B882' />
<link rel='icon' href='/static/favicon.ico' />
<meta property='og:url' content={props.url || defaultOGURL} />
<meta property='og:title' content={props.title || ''} />
<meta property='og:description' content={props.description || defaultDescription} />
<meta name='twitter:site' content={props.url || defaultOGURL} />
<meta name='twitter:card' content='summary_large_image' />
<meta name='twitter:image' content={props.ogImage || defaultOGImage} />
<meta property='og:image' content={props.ogImage || defaultOGImage} />
<meta property='og:image:width' content='1200' />
<meta property='og:image:height' content='630' />
</NextHead>
)
Head.propTypes = {
title: string,
description: string,
url: string,
ogImage: string
}
export default Head
import Link from 'next/link' import Link from 'next/link'
const links = [ const links = [
{ href: 'https://github.com/segmentio/create-next-app', label: 'Github' } { href: 'https://github.com/zeit/next.js', label: 'Github' },
].map(link => { { href: 'https://nextjs.org/docs', label: 'Docs' }
link.key = `nav-link-${link.href}-${link.label}` ]
return link
})
const Nav = () => ( export default function Nav () {
<nav> return <nav>
<ul> <ul className='flex justify-between items-center p-8'>
<li> <li className='list-reset'>
<Link prefetch href='/'> <Link prefetch href='/'>
<a>Home</a> <a className='text-blue no-underline'>Home</a>
</Link> </Link>
</li> </li>
<ul> <ul className='flex justify-between items-center'>
{links.map( {links.map(
({ key, href, label }) => ( ({ href, label }) => (
<li key={key}> <li key={`${href}${label}`} className='list-reset ml-4'>
<Link href={href}> <Link href={href}>
<a className='btn-blue'>{label}</a> <a className='btn-blue no-underline'>{label}</a>
</Link> </Link>
</li> </li>
) )
)} )}
</ul> </ul>
</ul> </ul>
<style jsx>{`
:global(body) {
margin: 0;
font-family: -apple-system,BlinkMacSystemFont,Avenir Next,Avenir,Helvetica,sans-serif;
}
nav {
text-align: center;
}
ul {
display: flex;
justify-content: space-between;
}
nav > ul {
padding: 4px 16px;
}
li {
display: flex;
padding: 6px 8px;
}
a {
color: #067df7;
text-decoration: none;
font-size: 13px;
}
`}</style>
</nav> </nav>
) }
export default Nav
const withCSS = require('@zeit/next-css')
module.exports = withCSS({})
...@@ -2,13 +2,12 @@ ...@@ -2,13 +2,12 @@
"name": "with-tailwindcss", "name": "with-tailwindcss",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"dev": "next & yarn dev:css", "dev": "next",
"dev:css": "postcss styles/index.css --watch -c styles/config/postcss.config.js -o static/css/bundle.css", "build": "next build",
"build": "next build & yarn build:css",
"build:css": "postcss styles/index.css -c styles/config/postcss.config.js -o static/css/bundle.css",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@zeit/next-css": "^1.0.1",
"next": "latest", "next": "latest",
"react": "^16.0.0", "react": "^16.0.0",
"react-dom": "^16.0.0" "react-dom": "^16.0.0"
...@@ -16,8 +15,7 @@ ...@@ -16,8 +15,7 @@
"devDependencies": { "devDependencies": {
"autoprefixer": "^7.1.6", "autoprefixer": "^7.1.6",
"cssnano": "^3.10.0", "cssnano": "^3.10.0",
"postcss-cli": "^4.1.1",
"postcss-easy-import": "^3.0.0", "postcss-easy-import": "^3.0.0",
"tailwindcss": "^0.2.2" "tailwindcss": "^0.6.6"
} }
} }
import '../styles/index.css'
import React from 'react'
import App, { Container } from 'next/app'
export default class MyApp extends App {
render () {
const { Component, pageProps } = this.props
return (
<Container>
<Component {...pageProps} />
</Container>
)
}
}
import Document, { Head, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static getInitialProps ({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage()
return { html, head, errorHtml, chunks }
}
render () {
return (
<html>
<Head>
<link rel='stylesheet' href='/static/css/bundle.css' />
</Head>
<body>
{this.props.customValue}
<Main />
<NextScript />
</body>
</html>
)
}
}
export default MyDocument
import Head from '../components/head'
import Nav from '../components/nav' import Nav from '../components/nav'
export default () => ( export default () => (
<div> <div>
<Head title='Home' />
<Nav /> <Nav />
<div className='hero'> <div className='hero'>
<h1 className='title'>Next.js + Tailwind css</h1> <h1 className='title'>Next.js + Tailwind css</h1>
......
...@@ -3,8 +3,7 @@ var tailwindcss = require('tailwindcss') ...@@ -3,8 +3,7 @@ var tailwindcss = require('tailwindcss')
module.exports = { module.exports = {
plugins: [ plugins: [
require('postcss-easy-import'), require('postcss-easy-import'),
tailwindcss('./styles/config/tailwind.config.js'), tailwindcss('./tailwind.config.js'),
require('autoprefixer'), require('autoprefixer')
require('cssnano')
] ]
} }
...@@ -19,37 +19,3 @@ ...@@ -19,37 +19,3 @@
.title, .description { .title, .description {
text-align: center; text-align: center;
} }
.row {
max-width: 880px;
margin: 80px auto 40px;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.card {
padding: 18px 18px 24px;
width: 220px;
text-align: left;
text-decoration: none;
color: #434343;
border: 1px solid #9B9B9B;
}
.card:hover {
border-color: #067df7;
}
.card h3 {
margin: 0;
color: #067df7;
font-size: 18px;
}
.card p {
margin: 0;
padding: 12px 0 0;
font-size: 13px;
color: #333;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment