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

Commit bc0afaa

Browse files
committed
Add a production build script with Purgecss and cssnano
1 parent ab26f13 commit bc0afaa

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,19 @@ To get started:
3333
Now you should be able to see the project running at localhost:8080.
3434

3535
4. Open `index.html` in your editor and start experimenting!
36+
37+
## Building for production
38+
39+
Even though this isn't necessarily a starter kit for a proper project, we've included an example of setting up both [Purgecss](https://www.purgecss.com/) and [cssnano](https://cssnano.co/) to optimize your CSS for production.
40+
41+
To build an optimized version of your CSS, simply run:
42+
43+
```bash
44+
# Using npm
45+
npm run production
46+
47+
# Using Yarn
48+
yarn run production
49+
```
50+
51+
After that's done, check out `./dist/tailwind.css` to see the optimized output.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"scripts": {
3-
"serve": "concurrently \"postcss tailwind.css -o dist/tailwind.css --watch\" \"live-server .\""
3+
"serve": "NODE_ENV=development concurrently \"postcss tailwind.css -o dist/tailwind.css --watch\" \"live-server .\"",
4+
"development": "NODE_ENV=development postcss tailwind.css -o dist/tailwind.css",
5+
"production": "NODE_ENV=production postcss tailwind.css -o dist/tailwind.css"
46
},
57
"dependencies": {
68
"autoprefixer": "^9.5.1",
79
"tailwindcss": "^1.0.0-beta.8"
810
},
911
"devDependencies": {
12+
"@fullhuman/postcss-purgecss": "^1.2.0",
1013
"concurrently": "^4.1.0",
14+
"cssnano": "^4.1.10",
1115
"live-server": "^1.2.1",
1216
"postcss-cli": "^6.1.2"
1317
}

postcss.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
const purgecss = require('@fullhuman/postcss-purgecss')({
2+
content: ['./*.html'],
3+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
4+
})
5+
16
module.exports = {
27
plugins: [
38
require('tailwindcss'),
49
require('autoprefixer'),
10+
...process.env.NODE_ENV === 'production'
11+
? [purgecss, require('cssnano')]
12+
: []
513
]
614
}

0 commit comments

Comments
 (0)