Skip to content

Commit ae44109

Browse files
timneutkensarunoda
authored andcommitted
Add styled-jsx-plugin-sass example (vercel#3104)
* Upgrade dependency on next * Add styled-jsx-plugin-sass example * Update readme
1 parent 9b129f8 commit ae44109

5 files changed

Lines changed: 89 additions & 1 deletion

File tree

examples/with-styled-jsx-plugins/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"lost": "8.2.0",
11-
"next": "4.0.4",
11+
"next": "4.1.0",
1212
"postcss-nested": "2.1.2",
1313
"react": "16.0.0",
1414
"react-dom": "16.0.0",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"next/babel",
5+
{
6+
"styled-jsx": {
7+
"plugins": [
8+
"styled-jsx-plugin-sass"
9+
]
10+
}
11+
}
12+
]
13+
]
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[![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-styled-jsx-scss)
2+
3+
# With styled-jsx SASS / SCSS
4+
5+
## How to use
6+
7+
Download the example [or clone the repo](https://github.com/zeit/next.js):
8+
9+
```bash
10+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-styled-jsx-scss
11+
cd with-styled-jsx-scss
12+
```
13+
14+
Install it and run:
15+
16+
```bash
17+
npm install
18+
npm run dev
19+
```
20+
21+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
22+
23+
```bash
24+
now
25+
```
26+
27+
## The idea behind the example
28+
29+
Next.js ships with [styled-jsx](https://github.com/zeit/styled-jsx) allowing you
30+
to write scope styled components with full css support. This is important for
31+
the modularity and code size of your bundles and also for the learning curve of the framework. If you know css you can write styled-jsx right away.
32+
33+
This example shows how to configure styled-jsx to use external plugins to modify the output. Using this you can use PostCSS, SASS (SCSS), LESS, or any other pre-processor with styled-jsx. You can define plugins in `.babelrc`. This example shows how to implement the SASS plugin.
34+
35+
More details about how plugins work can be found in the [styled-jsx readme](https://github.com/zeit/styled-jsx#css-preprocessing-via-plugins)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "basic-css",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"next": "4.1.0",
11+
"node-sass": "4.5.3",
12+
"react": "16.0.0",
13+
"react-dom": "16.0.0",
14+
"styled-jsx-plugin-sass": "0.1.0"
15+
},
16+
"license": "ISC"
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default () => (
2+
<div className='hello'>
3+
<p>Hello World</p>
4+
<style jsx>{`
5+
$color: red;
6+
7+
.hello {
8+
background: #eee;
9+
padding: 100px;
10+
text-align: center;
11+
transition: 100ms ease-in background;
12+
&:hover {
13+
color: $color;
14+
}
15+
16+
@media only screen and (max-width: 480px) {
17+
font-size: 20px;
18+
}
19+
}
20+
`}</style>
21+
</div>
22+
)

0 commit comments

Comments
 (0)