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

Commit 406a439

Browse files
authored
Merge pull request #14 from brandonpittman/master
Use plugin
2 parents e4fd35d + 6ce3110 commit 406a439

5 files changed

Lines changed: 24 additions & 153 deletions

File tree

examples/gridsome/README.md

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,18 @@
1-
# gridsome
1+
# Gridsome
22

33
If you don't have an existing Gridsome project, check out their docs on how to get started.
44

5-
Once you have a Gridsome site, install Tailwind by running this in the root of the project:
5+
This plugin makes use of the gridsome-plugin-tailwindcss plugin to add
6+
Tailwind, PurgeCSS, postcss-preset-env, and postcss-import to your build chain.
7+
It includes both gridsome-plugin-tailwindcss and the regular tailwindcss so
8+
that you can write your own plugins and access the default config in
9+
`tailwind.config.js`.
610

7-
```
8-
npm install tailwindcss
9-
```
11+
The plugin adds Tailwind directives under the hood using Gridsome's Client API
12+
so Tailwind works out-of-the-box, requiring no further declaration of Tailwind
13+
directives.
1014

11-
More than likely, you want to use PurgeCSS as well, so let's install that too:
15+
It's recommended to use `tailwind.config.js` to add [global base styles](https://tailwindcss.com/docs/adding-base-styles#using-a-plugin),
16+
components, and utilities instead of adding them in CSS files.
1217

13-
```
14-
npm install @fullhuman/postcss-purgecss
15-
```
16-
17-
Next, initialize your Tailwind config:
18-
19-
```
20-
./node_modules/.bin/tailwind init
21-
```
22-
23-
Then in `gridsome.config.js`, require Tailwind and add it as a PostCSS plugin, as well as our PurgeCSS config:
24-
25-
```js
26-
// gridsome.config.js
27-
const purgecss = require('@fullhuman/postcss-purgecss')
28-
const tailwind = require('tailwindcss')
29-
30-
const postcssPlugins = [
31-
tailwind('./tailwind.config.js'),
32-
]
33-
34-
// add purgecss only when building for production
35-
if (process.env.NODE_ENV === 'production') postcssPlugins.push(purgecss())
36-
37-
module.exports = {
38-
css: {
39-
loaderOptions: {
40-
postcss: {
41-
plugins: postcssPlugins,
42-
},
43-
},
44-
},
45-
}
46-
```
47-
48-
Now let's create a `purgecss.config.js` file to define some options for PurgeCSS:
49-
50-
```js
51-
// purgecss.config.js
52-
53-
class TailwindExtractor {
54-
static extract(content) {
55-
return content.match(/[A-z0-9-:\\/]+/g)
56-
}
57-
}
58-
59-
module.exports = {
60-
content: [
61-
'./src/**/*.vue',
62-
'./src/**/*.js',
63-
'./src/**/*.jsx',
64-
'./src/**/*.html',
65-
'./src/**/*.pug',
66-
'./src/**/*.md',
67-
],
68-
whitelist: [
69-
'body',
70-
'html',
71-
'img',
72-
'a',
73-
'g-image',
74-
'g-image--lazy',
75-
'g-image--loaded',
76-
],
77-
extractors: [
78-
{
79-
extractor: TailwindExtractor,
80-
extensions: ['vue', 'js', 'jsx', 'md', 'html', 'pug'],
81-
},
82-
],
83-
}
84-
```
85-
86-
Next up, we'll create a file at `src/assets/tailwind.css`:
87-
88-
```css
89-
@tailwind base;
90-
@tailwind components;
91-
@tailwind utilities;
92-
```
93-
94-
Finally, we'll import that into our `src/main.js` file:
95-
96-
```js
97-
import DefaultLayout from '~/layouts/Default.vue'
98-
import '~/assets/tailwind.css'
99-
100-
export default function (Vue, { router, head, isClient }) {
101-
// Set default layout as a global component
102-
Vue.component('Layout', DefaultLayout)
103-
}
104-
```
105-
106-
Now you should be all set to start using Tailwind and PurgeCSS in your Gridsome project!
18+
Now you should be all set to start using Tailwind, postcss-preset-env, postcss-import, and PurgeCSS in your Gridsome project!
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
const purgecss = require('@fullhuman/postcss-purgecss')
2-
const tailwind = require('tailwindcss')
3-
4-
const postcssPlugins = [
5-
tailwind('./tailwind.config.js'),
6-
]
7-
8-
// add purgecss only when building for production
9-
if (process.env.NODE_ENV === 'production') postcssPlugins.push(purgecss())
10-
111
module.exports = {
122
siteName: 'Gridsome Tailwind Setup',
13-
css: {
14-
loaderOptions: {
15-
postcss: {
16-
plugins: postcssPlugins,
17-
},
3+
plugins: [
4+
{
5+
use: 'gridsome-plugin-tailwindcss',
186
},
19-
},
20-
}
7+
],
8+
}
9+

examples/gridsome/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"explore": "gridsome explore"
88
},
99
"dependencies": {
10-
"@fullhuman/postcss-purgecss": "^1.2.0",
11-
"gridsome": "^0.6.0",
12-
"tailwindcss": "^1.0.3"
10+
"gridsome": "latest",
11+
"gridsome-plugin-tailwindcss": "latest"
1312
}
1413
}

examples/gridsome/purgecss.config.js

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const defaultTheme = require('tailwindcss/defaultTheme')
2+
13
module.exports = {
24
theme: {
3-
extend: {}
5+
extend: {},
46
},
57
variants: {},
6-
plugins: []
8+
plugins: [],
79
}

0 commit comments

Comments
 (0)