Comparing version 0.13.0 to 0.13.1
{ | ||
"name": "purgecss", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"description": "Remove unused css selectors.", | ||
@@ -12,3 +12,4 @@ "main": "./lib/purgecss.js", | ||
"lib": "lib", | ||
"test": "__tests__" | ||
"test": "__tests__", | ||
"example": "examples" | ||
}, | ||
@@ -61,3 +62,3 @@ "bin": "./bin/purgecss", | ||
"regenerator-runtime": "^0.11.0", | ||
"rollup": "^0.51.7", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
@@ -64,0 +65,0 @@ "rollup-plugin-commonjs": "^8.2.3", |
319
README.md
@@ -1,4 +0,8 @@ | ||
# Purgecss | ||
[![Build Status](https://travis-ci.org/FullHuman/purgecss.svg?branch=master)](https://travis-ci.org/FullHuman/purgecss) [![CircleCi](https://circleci.com/gh/FullHuman/purgecss/tree/master.svg?style=shield)]() [![dependencies Status](https://david-dm.org/fullhuman/purgecss/status.svg)](https://david-dm.org/fullhuman/purgecss) [![devDependencies Status](https://david-dm.org/fullhuman/purgecss/dev-status.svg)](https://david-dm.org/fullhuman/purgecss?type=dev) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2f2f3fb0a5c541beab2018483e62a828)](https://www.codacy.com/app/FullHuman/purgecss?utm_source=github.com&utm_medium=referral&utm_content=FullHuman/purgecss&utm_campaign=Badge_Grade) | ||
# Purgecss | ||
[![Build Status](https://travis-ci.org/FullHuman/purgecss.svg?branch=master)](https://travis-ci.org/FullHuman/purgecss) | ||
[![CircleCi](https://circleci.com/gh/FullHuman/purgecss/tree/master.svg?style=shield)]() | ||
[![dependencies Status](https://david-dm.org/fullhuman/purgecss/status.svg)](https://david-dm.org/fullhuman/purgecss) | ||
[![devDependencies Status](https://david-dm.org/fullhuman/purgecss/dev-status.svg)](https://david-dm.org/fullhuman/purgecss?type=dev) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2f2f3fb0a5c541beab2018483e62a828)](https://www.codacy.com/app/FullHuman/purgecss?utm_source=github.com&utm_medium=referral&utm_content=FullHuman/purgecss&utm_campaign=Badge_Grade) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/2f2f3fb0a5c541beab2018483e62a828)](https://www.codacy.com/app/FullHuman/purgecss?utm_source=github.com&utm_medium=referral&utm_content=FullHuman/purgecss&utm_campaign=Badge_Coverage) | ||
@@ -8,3 +12,2 @@ [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
<p align="center"> | ||
@@ -14,23 +17,25 @@ <img src="./.assets/logo.png" height="200" width="200" alt="Purgecss logo"/> | ||
* [What is purgecss?](#what-is-purgecss) | ||
* [Getting started](#getting-started) | ||
* [Usage](#usage) | ||
* [Build plugin](#build-plugin) | ||
* [CLI](#cli) | ||
* [Differences with](#differences-with) | ||
* [Contributing](#contributing) | ||
- [What is purgecss?](#what-is-purgecss) | ||
- [Getting started](#getting-started) | ||
- [Usage](#usage) | ||
- [Build plugin](#build-plugin) | ||
- [CLI](#cli) | ||
- [Differences with](#differences-with) | ||
- [Contributing](#contributing) | ||
## What is purgecss? | ||
Purgecss is a tool inspired by Purifycss to remove unused css. Originally thought as the v2 of purifycss, | ||
purgecss has for goal to act in a similar way while correcting the known problems of purifycss. If you want | ||
to know more about the differences between purifycss and purgecss, go to the section [Differences with](#differences-with). | ||
When you are building a website, chances are that you are using a css framework. Bootstrap, Materializecss, Foundation are | ||
some of the big css framework that you can include to your website, but you will only use a small set of the framework and | ||
a lot of unused css styles will be included. | ||
This is where Purgecss comes into play. Purgecss takes your content and your css and matches the selectors used in your files | ||
with the one in your content files. It removes every unused selectors from your css files, resulting in smaller, optimize css | ||
files. | ||
Purgecss is a tool inspired by Purifycss to remove unused css. Originally | ||
thought as the v2 of purifycss, purgecss has for goal to act in a similar way | ||
while correcting the known problems of purifycss. If you want to know more about | ||
the differences between purifycss and purgecss, go to the section [Differences | ||
with](#differences-with).\ | ||
When you are building a website, chances are that you are using a css framework. | ||
Bootstrap, Materializecss, Foundation are some of the big css framework that you | ||
can include to your website, but you will only use a small set of the framework and | ||
a lot of unused css styles will be included.\ | ||
This is where Purgecss comes into play. Purgecss takes your content and your css | ||
and matches the selectors used in your files with the one in your content files. | ||
It removes every unused selectors from your css files, resulting in smaller, | ||
optimize css files. | ||
@@ -45,21 +50,9 @@ ### Getting Started | ||
### Documentation | ||
- [API](./docs/API.md) | ||
- [Extractor](./docs/Extractor.md) | ||
### Usage | ||
```js | ||
import Purgecss from "purgecss" | ||
import purgeHtml from "purge-from-html" | ||
import Purgecss from 'purgecss' | ||
const purgeCss = new Purgecss({ | ||
content: ["**/*.html"], | ||
css: ["**/*.css"], | ||
extractors: [ | ||
{ | ||
extractor: purgeHtml, | ||
extensions: ["html"] | ||
} | ||
] | ||
content: ['**/*.html'], | ||
css: ['**/*.css'] | ||
}) | ||
@@ -69,2 +62,18 @@ const result = purgecss.purge() | ||
```js | ||
import Purgecss from 'purgecss' | ||
import purgeHtml from 'purge-from-html' | ||
const purgeCss = new Purgecss({ | ||
content: ['**/*.html'], | ||
css: ['**/*.css'], | ||
extractors: [ | ||
{ | ||
extractor: purgeHtml, | ||
extensions: ['html'] | ||
} | ||
] | ||
}) | ||
const result = purgecss.purge() | ||
``` | ||
#### Build Plugin | ||
@@ -91,7 +100,10 @@ | ||
gulp.task('purgecss', () => { | ||
return gulp.src('src/**/*.css') | ||
.pipe(purgecss({ | ||
content: ["src/**/*.html"] | ||
})) | ||
.pipe(gulp.dest('build/css')) | ||
return gulp | ||
.src('src/**/*.css') | ||
.pipe( | ||
purgecss({ | ||
content: ['src/**/*.html'] | ||
}) | ||
) | ||
.pipe(gulp.dest('build/css')) | ||
}) | ||
@@ -102,3 +114,2 @@ ``` | ||
```js | ||
@@ -111,29 +122,29 @@ const path = require('path') | ||
const PATHS = { | ||
src: path.join(__dirname, 'src') | ||
src: path.join(__dirname, 'src') | ||
} | ||
module.exports = { | ||
entry: './src/index.js', | ||
output: { | ||
filename: 'bundle.js', | ||
path: path.join(__dirname, 'dist') | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: 'css-loader?sourceMap' | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('[name].css?[hash]'), | ||
new PurgecssPlugin({ | ||
paths: glob.sync(`${PATHS.src}/*`), | ||
styleExtensions: ['.css'] | ||
entry: './src/index.js', | ||
output: { | ||
filename: 'bundle.js', | ||
path: path.join(__dirname, 'dist') | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: 'css-loader?sourceMap' | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('[name].css?[hash]'), | ||
new PurgecssPlugin({ | ||
paths: glob.sync(`${PATHS.src}/*`), | ||
styleExtensions: ['.css'] | ||
}) | ||
] | ||
} | ||
@@ -145,13 +156,13 @@ ``` | ||
```js | ||
import { rollup } from 'rollup'; | ||
import purgecss from 'rollup-plugin-purgecss'; | ||
import { rollup } from 'rollup' | ||
import purgecss from 'rollup-plugin-purgecss' | ||
rollup({ | ||
entry: 'main.js', | ||
plugins: [ | ||
purgecss({ | ||
content: ["index.html"] | ||
}) | ||
] | ||
}); | ||
entry: 'main.js', | ||
plugins: [ | ||
purgecss({ | ||
content: ['index.html'] | ||
}) | ||
] | ||
}) | ||
``` | ||
@@ -174,30 +185,34 @@ | ||
You can see an example of how to use the CLI [here](./examples/cli/config-file/) | ||
### Extractor | ||
Purgecss can be adapted to suit your need. If you want to purify exclusively html file, you might want | ||
to consider the _purge-from-html_ extractor. | ||
Purgecss relies on extractors to get the list of selector used in a file. | ||
There are multiples types of files that can contains selectors such as html files, templating files like pug, or even javascript file. | ||
Purgecss can be adapted to suit your need. If you want to purify exclusively | ||
html file, you might want to consider the _purge-from-html_ extractor.\ | ||
Purgecss relies on extractors to get the list of selector used in a file. There are | ||
multiples types of files that can contains selectors such as html files, templating | ||
files like pug, or even javascript file. | ||
#### Using an extractor | ||
You can use an extractor by settings the extractors option in the purgecss config file. | ||
You can use an extractor by settings the extractors option in the purgecss | ||
config file. | ||
```js | ||
import purgeJs from "purgecss-from-js" | ||
import purgeHtml from "purge-from-html" | ||
import purgeJs from 'purgecss-from-js' | ||
import purgeHtml from 'purge-from-html' | ||
const options = { | ||
content: [],// files to extract the selectors from | ||
css: [],// css | ||
extractors: [ | ||
{ | ||
extractor: purgeJs, | ||
extensions: ["js"] | ||
}, | ||
{ | ||
extractor: purgeHtml, | ||
extensions: ["html"] | ||
} | ||
] | ||
content: [], // files to extract the selectors from | ||
css: [], // css | ||
extractors: [ | ||
{ | ||
extractor: purgeJs, | ||
extensions: ['js'] | ||
}, | ||
{ | ||
extractor: purgeHtml, | ||
extensions: ['html'] | ||
} | ||
] | ||
} | ||
@@ -209,30 +224,33 @@ export default options | ||
Purgecss provides a default extractor that is working with all types of files but can be limited and not fit exactly the type of files that you are using. | ||
The default extractor considers every word of a file as a selector. | ||
The default extractor has a few limitations: | ||
- Do not consider special characters such as `@`. | ||
Purgecss provides a default extractor that is working with all types of files | ||
but can be limited and not fit exactly the type of files that you are using.\ | ||
The default extractor considers every word of a file as a selector. The default extractor | ||
has a few limitations: | ||
* Do not consider special characters such as `@`. | ||
#### Legacy extractor | ||
The legacy extractor reproduces the behavior of _purifycss_. You can use the Legacy extractor by setting the option `legacy: true`. | ||
The legacy extractor has a few limitations: | ||
- Do not extract uppercase selector | ||
- Do not extract numbers | ||
The legacy extractor reproduces the behavior of *purifycss*. You can use the | ||
Legacy extractor by setting the option `legacy: true`. The legacy extractor has | ||
a few limitations: | ||
* Do not extract uppercase selector | ||
* Do not extract numbers | ||
#### Create an extractor | ||
An extractor is a simple class with one method. The method `extract` takes the content of a file as a string and return an array of selectors. | ||
By convention, the name of the npm package is `purge-from-[typefile]` (e.g. purge-from-pug). You can look at the list of extractor on npm by searching `purge-from`. | ||
An extractor is a simple class with one method. The method `extract` takes the | ||
content of a file as a string and return an array of selectors. By convention, | ||
the name of the npm package is `purge-from-[typefile]` (e.g. purge-from-pug). | ||
You can look at the list of extractor on npm by searching `purge-from`. | ||
```js | ||
class PurgeFromJs { | ||
static extract(content) { | ||
// return array of css selectors | ||
} | ||
static extract(content) { | ||
// return array of css selectors | ||
} | ||
} | ||
``` | ||
### Differences with | ||
@@ -242,12 +260,17 @@ | ||
The biggest flaw with purifycss is its lack of modularity. It is also is biggest benefit, purifycss can work with any files, | ||
not just html or javascript. But purifycss works by looking at all the words in the files and comparing them with the selectors | ||
in the css. Every words is consider a selector, which means that a lot of selectors can be consider used because you have the | ||
selector name in a paragraph or somewhere in your files. | ||
The biggest flaw with purifycss is its lack of modularity. It is also is biggest | ||
benefit, purifycss can work with any files, not just html or javascript. But | ||
purifycss works by looking at all the words in the files and comparing them with | ||
the selectors in the css. Every words is consider a selector, which means that a | ||
lot of selectors can be consider used because you have the selector name in a | ||
paragraph or somewhere in your files. | ||
Purgecss fixes this problem by providing the possibility to create an _extractor_, an extractor is a function that takes the content | ||
of a file and extract the list of css selectors in it. It allows a perfect removal of unused css. The extractor can used a parser | ||
that returns an ast and then looks through it to select the css selectors. That is the way `purge-from-html` works. | ||
You can specified which selectors you want to use for each types of files, and so, get the most accurate results. | ||
You can still use the default or the legacy extractor that will act the same way as purifycss. | ||
Purgecss fixes this problem by providing the possibility to create an | ||
*extractor*, an extractor is a function that takes the content of a file and | ||
extract the list of css selectors in it. It allows a perfect removal of unused | ||
css. The extractor can used a parser that returns an ast and then looks through | ||
it to select the css selectors. That is the way `purge-from-html` works. You can | ||
specified which selectors you want to use for each types of files, and so, get | ||
the most accurate results. You can still use the default or the legacy extractor | ||
that will act the same way as purifycss. | ||
@@ -257,39 +280,48 @@ #### Uncss | ||
As indicated in its Readme, Uncss works the following way: | ||
1. The HTML files are loaded by jsdom and JavaScript is executed. | ||
2. All the stylesheets are parsed by PostCSS. | ||
3. document.querySelector filters out selectors that are not found in the HTML files. | ||
3. document.querySelector filters out selectors that are not found in the HTML | ||
files. | ||
4. The remaining rules are converted back to CSS. | ||
Because of the emulation of html, and the execution of javascript, uncss is effective at removing unused selectors from web application. | ||
But the emulation can have a cost in term of performance and practicality. Uncss works by emulating the html files. To remove unused css | ||
from pug template files, you will need to convert pug to html and then emulate the page inside jsdom and uncss will run `document.querySelector` | ||
on each selectors and step 4. | ||
Uncss by its design is probably the most accurate tool to remove css out of a web application at this moment. | ||
Because of the emulation of html, and the execution of javascript, uncss is | ||
effective at removing unused selectors from web application. But the emulation | ||
can have a cost in term of performance and practicality. Uncss works by | ||
emulating the html files. To remove unused css from pug template files, you will | ||
need to convert pug to html and then emulate the page inside jsdom and uncss | ||
will run `document.querySelector` on each selectors and step 4.\ | ||
Uncss by its design is probably the most accurate tool to remove css out of a web | ||
application at this moment. | ||
Purgecss does not have an extractor right now for javascript files. But because of its modularity, developers can create an extractor for specific | ||
framework (vue, react, aurelia) and files (pug, ejs) and get the most accurate result without the need of emulation. | ||
Purgecss does not have an extractor right now for javascript files. But because | ||
of its modularity, developers can create an extractor for specific framework | ||
(vue, react, aurelia) and files (pug, ejs) and get the most accurate result | ||
without the need of emulation. | ||
## Contributing | ||
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. | ||
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of | ||
conduct, and the process for submitting pull requests to us. | ||
## Versioning | ||
Purgecss use [SemVer](http://semver.org/) for versioning. | ||
Purgecss use [SemVer](http://semver.org/) for versioning. | ||
## Acknowledgment | ||
Purgecss was originally thought as the v2 of purifycss. And because of it, it is greatly inspired by it. | ||
The plugins such as purgecss-webpack-plugin are based on the purifycss plugin. | ||
Below is the list of the purifycss repositories: | ||
- [purifycss](https://github.com/purifycss/purifycss) | ||
- [gulp-purifycss](https://github.com/purifycss/gulp-purifycss) | ||
- [purifycss-webpack](https://github.com/webpack-contrib/purifycss-webpack) | ||
Purgecss was originally thought as the v2 of purifycss. And because of it, it is | ||
greatly inspired by it.\ | ||
The plugins such as purgecss-webpack-plugin are based on the purifycss plugin.\ | ||
Below is the list of the purifycss repositories: | ||
* [purifycss](https://github.com/purifycss/purifycss) | ||
* [gulp-purifycss](https://github.com/purifycss/gulp-purifycss) | ||
* [purifycss-webpack](https://github.com/webpack-contrib/purifycss-webpack) | ||
## License | ||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file | ||
for details. | ||
## Troubleshooting | ||
@@ -299,3 +331,6 @@ | ||
The extractors needs to be defined from the more specific to the less specific. Meaning that you need to define `js` extractor after `ejs`. So the `js` extractor will not be selected for ejs files. | ||
The extractors needs to be defined from the more specific to the less specific. | ||
Meaning that you need to define `js` extractor after `ejs`. So the `js` | ||
extractor will not be selected for ejs files. | ||
> You can specified extensions like `.es.js`. | ||
@@ -305,6 +340,4 @@ | ||
If you are using the default or legacy extractor, look here. | ||
Head over the repository of the extractor and open an issue. | ||
Be as precise as possible when describing the issue, provide the | ||
css file and content file if possible. | ||
If you are using the default or legacy extractor, look here. Head over the | ||
repository of the extractor and open an issue. Be as precise as possible when | ||
describing the issue, provide the css file and content file if possible. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
845356
97
22794
330