Commit 2f325e0f authored by Danil Shashkov's avatar Danil Shashkov Committed by Luis Fernando Alvarez D

Add example with astroturf (Zero runtime CSS-in-JS) (#6821)

* Add example with astroturf (Zero runtime CSS-in-JS)
parent 51b15417
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-astroturf)
# Example app with [astroturf](https://github.com/4Catalyzer/astroturf)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example with-astroturf with-astroturf-app
# or
yarn create next-app --example with-astroturf with-astroturf-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-astroturf
cd with-astroturf
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn 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 to use [astroturf](https://github.com/4Catalyzer/astroturf) as the zero-runtime CSS-in-JS styling solution instead of [styled-jsx](https://github.com/zeit/styled-jsx).
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
cssModules: true,
webpack: config => {
config.module.rules.push({
test: /\.js$/,
use: ['astroturf/loader']
})
return config
}
})
{
"name": "with-astroturf",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@zeit/next-css": "^1.0.1",
"astroturf": "^0.9.2",
"next": "^8.0.3",
"postcss-nested": "^4.1.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"license": "ISC"
}
import React from 'react'
import styled from 'astroturf'
const Button = styled('button')`
color: black;
border: 1px solid black;
background-color: white;
&.primary {
color: blue;
border: 1px solid blue;
}
&.color-green {
color: green;
}
`
const IndexPage = () => (
<Button primary color='green'>
A styled button
</Button>
)
export default IndexPage
module.exports = {
plugins: {
'postcss-nested': {}
}
}
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-emotion) [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-linaria)
# Example app with [linaria](https://linaria.now.sh/) # Example app with [linaria](https://linaria.now.sh/)
......
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