Skip to content

Commit 98003e2

Browse files
authored
Merge pull request #1 from rongierlach/purify-css
Purify css
2 parents f0f3fff + 234bf11 commit 98003e2

File tree

6 files changed

+113
-70
lines changed

6 files changed

+113
-70
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# Gatsby Plugin Uncss
1+
# Gatsby Plugin PurifyCSS
22
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3-
[![npm version](https://badge.fury.io/js/gatsby-plugin-uncss.svg)](https://badge.fury.io/js/gatsby-plugin-uncss) [![dependencies Status](https://david-dm.org/rongierlach/gatsby-plugin-uncss/status.svg)](https://david-dm.org/rongierlach/gatsby-plugin-uncss) [![devDependencies Status](https://david-dm.org/rongierlach/gatsby-plugin-uncss/dev-status.svg)](https://david-dm.org/rongierlach/gatsby-plugin-uncss?type=dev)
4-
A [Gatsby](https://github.com/gatsbyjs/gatsby) post-build plugin that implements [Uncss](https://github.com/giakki/uncss).
3+
[![npm version](https://badge.fury.io/js/gatsby-plugin-purify-css.svg)](https://badge.fury.io/js/gatsby-plugin-purify-css) [![dependencies Status](https://david-dm.org/rongierlach/gatsby-plugin-purify-css/status.svg)](https://david-dm.org/rongierlach/gatsby-plugin-purify-css) [![devDependencies Status](https://david-dm.org/rongierlach/gatsby-plugin-purify-css/dev-status.svg)](https://david-dm.org/rongierlach/gatsby-plugin-purify-css?type=dev)
4+
A [Gatsby](https://github.com/gatsbyjs/gatsby) post-build plugin that implements [PurifyCSS](https://github.com/purifycss/purifycss).
55
Never worry about the size of your css framework again!
66
It updates your html files directly, removing any unused inline styles.
77

88
## Install
9-
`$ npm install gatsby-plugin-uncss`
9+
`$ npm install gatsby-plugin-purify-css`
1010

1111
## Usage
1212
In your `gatsby-config.js` file:
1313
```javascript
1414
module.exports = {
1515
plugins: [
1616
{
17-
resolve: 'gatsby-plugin-uncss'
17+
resolve: 'gatsby-plugin-purify-css'
1818
options: {
19-
uncssOptions: { /* ... */ }
19+
purifyOptions: { /* ... */ }
2020
}
2121
}
2222
]
2323
}
2424
```
2525

2626
## Options
27-
Uncss options are documented [here](https://github.com/giakki/uncss#within-nodejs).
27+
PurifyCSS options are documented [here](https://github.com/purifycss/purifycss#the-optional-options-argument).

example/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Project dependencies
2+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3+
node_modules
4+
.cache/
5+
# Build directory
6+
public/
7+
.DS_Store
8+
yarn-error.log
9+
yarn.lock

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"dependencies": {
1414
"gatsby": "^1.9.38",
1515
"gatsby-link": "^1.6.16",
16-
"gatsby-plugin-uncss": "^1.0.0"
16+
"gatsby-plugin-uncss": "^1.1.0"
1717
}
1818
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "gatsby-plugin-uncss",
3-
"version": "1.1.0",
2+
"name": "gatsby-plugin-purify-css",
3+
"version": "0.0.0",
44
"description": "Gatsby plugin for removing unused CSS in production.",
55
"keywords": [
66
"gatsby",
77
"plugin",
8-
"uncss",
98
"purify",
9+
"uncss",
1010
"css"
1111
],
1212
"main": "index.js",
@@ -17,16 +17,16 @@
1717
"build": "webpack",
1818
"prepublishOnly": "npm run clean && npm run build"
1919
},
20-
"repository": "git@github.com:rongierlach/gatsby-plugin-uncss.git",
20+
"repository": "git@github.com:rongierlach/gatsby-plugin-purify-css.git",
2121
"author": "Ron Gierlach <rongierlach@gmail.com>",
2222
"license": "GPL-3.0",
2323
"dependencies": {
2424
"bluebird": "^3.5.0",
2525
"cheerio": "^1.0.0-rc.2",
2626
"klaw": "^2.1.0",
27+
"purify-css": "^1.2.5",
2728
"strip-css-comments": "^3.0.0",
28-
"through2-filter": "^2.0.0",
29-
"uncss": "^0.15.0"
29+
"through2-filter": "^2.0.0"
3030
},
3131
"devDependencies": {
3232
"babel-eslint": "^8.0.0",

src/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import uncss from 'uncss'
1+
import purify from 'purify-css'
22
import { resolve } from 'path'
33
import { promisify, all } from 'bluebird'
44

@@ -7,9 +7,9 @@ import sanitizeCSS from './sanitizeCSS'
77
import getPathsWithExt from './getPathsWithExt'
88
import selectAndReplaceInFileFactory from './selectAndReplaceInFileFactory'
99

10-
const uncssAsync = promisify(uncss)
10+
const purifyAsync = promisify(purify)
1111

12-
exports.onPostBuild = async (_, { uncssOptions }, cb) => {
12+
exports.onPostBuild = async (_, {purifyOptions = {minify: true}}, cb) => {
1313
const rootPath = resolve('public')
1414

1515
// get file paths
@@ -18,11 +18,7 @@ exports.onPostBuild = async (_, { uncssOptions }, cb) => {
1818

1919
// evalute CSS
2020
let originalCSS = await readFile(cssFile, { encoding: 'utf-8' })
21-
let purifiedCSS = await uncssAsync(htmlFiles, {
22-
...uncssOptions,
23-
raw: originalCSS,
24-
htmlroot: rootPath
25-
})
21+
let purifiedCSS = await purifyAsync(htmlFiles, originalCSS, purifyOptions)
2622

2723
// remove comments, sourcemaps, and newlines
2824
purifiedCSS = sanitizeCSS(purifiedCSS)

0 commit comments

Comments
 (0)