Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.

Commit 974ac28

Browse files
authored
Merge pull request #50 from emilbryggare/master
Updated example for Next.js 9.2
2 parents e2ef32e + 5e67036 commit 974ac28

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

examples/nextjs/README.md

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# Next.js
22

3-
To add Tailwind to a Next project, start by installing `@zeit/next-css`, `tailwindcss`, `postcss-import` and `autoprefixer`:
3+
To add Tailwind to a Next (^9.2.0) project, start by installing `tailwindcss`, `postcss-import` and `autoprefixer`:
44

55
```sh
6-
npm install @zeit/next-css tailwindcss postcss-import autoprefixer
6+
npm install tailwindcss postcss-import autoprefixer --save
77
```
88

99
Next, set up your PostCSS plugins by creating a `postcss.config.js` file and adding the following configuration:
1010

1111
```js
1212
module.exports = {
1313
plugins: [
14-
require('postcss-import'),
15-
require('tailwindcss'),
16-
require('autoprefixer'),
14+
"postcss-import",
15+
"tailwindcss",
16+
"autoprefixer"
1717
]
18-
}
18+
};
19+
1920
```
2021

2122
Next, create a CSS file for your Tailwind styles. We've used `css/tailwind.css` for this example:
@@ -42,3 +43,32 @@ class MyApp extends App {
4243

4344
export default MyApp
4445
```
46+
## Setting up Purgecss (optional)
47+
To add Purgecss, start by installing `@fullhuman/postcss-purgecss`.
48+
49+
```sh
50+
npm install @fullhuman/postcss-purgecss --save
51+
```
52+
53+
Finally, add Purgecss to PostCSS plugins by updating the `postcss.config.js` file and adding the following configuration:
54+
55+
```js
56+
const purgecss = [
57+
"@fullhuman/postcss-purgecss",
58+
{
59+
content: ["./components/**/*.js", "./pages/**/*.js"],
60+
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
61+
}
62+
];
63+
module.exports = {
64+
plugins: [
65+
"postcss-import",
66+
"tailwindcss",
67+
"autoprefixer",
68+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
69+
]
70+
};
71+
72+
```
73+
74+
[Learn more about using Purgecss with Tailwind here.](https://tailwindcss.com/docs/controlling-file-size#setting-up-purgecss)

examples/nextjs/next.config.js

-3
This file was deleted.

examples/nextjs/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
},
88
"dependencies": {
99
"@fullhuman/postcss-purgecss": "^1.2.0",
10-
"@zeit/next-css": "^1.0.1",
11-
"autoprefixer": "^9.6.0",
12-
"next": "^8.1.0",
10+
"autoprefixer": "^9.7.4",
11+
"next": "^9.2.0",
1312
"postcss-import": "^12.0.1",
14-
"react": "^16.8.6",
15-
"react-dom": "^16.8.6",
16-
"tailwindcss": "^1.0.3"
13+
"react": "^16.12.0",
14+
"react-dom": "^16.12.0",
15+
"tailwindcss": "^1.1.4"
1716
}
1817
}

examples/nextjs/postcss.config.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const purgecss = require('@fullhuman/postcss-purgecss')({
2-
content: ['./components/**/*.js', './pages/**/*.js'],
3-
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
4-
})
5-
1+
const purgecss = [
2+
"@fullhuman/postcss-purgecss",
3+
{
4+
content: ["./components/**/*.js", "./pages/**/*.js"],
5+
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
6+
}
7+
];
68
module.exports = {
79
plugins: [
8-
require('postcss-import'),
9-
require('tailwindcss'),
10-
require('autoprefixer'),
11-
...(process.env.NODE_ENV === 'production' ? [purgecss] : []),
12-
],
13-
}
10+
"postcss-import",
11+
"tailwindcss",
12+
"autoprefixer",
13+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
14+
]
15+
};

0 commit comments

Comments
 (0)