├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2016 Ryan Zimmerman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # postcss-uncss 2 | [![npm](https://img.shields.io/npm/v/postcss-uncss.svg?maxAge=2592000)](https://www.npmjs.com/package/postcss-uncss) 3 | [![npm](https://img.shields.io/npm/l/postcss-uncss.svg?maxAge=2592000)](https://github.com/uncss/postcss-uncss/blob/master/LICENSE) 4 | 5 | Use [uncss](https://github.com/uncss/uncss) as a [PostCSS](https://github.com/postcss/postcss) plugin. 6 | 7 | ## About 8 | 9 | UnCSS is a tool that removes unused CSS from your stylesheets. It works across multiple files and supports Javascript-injected CSS. 10 | 11 | ### Example: 12 | 13 | **html:** 14 | ```html 15 | 16 |

Hello World!

17 | 18 | ``` 19 | 20 | **css before:** 21 | ```css 22 | .red { 23 | color: red; 24 | } 25 | .blue { 26 | color: blue; 27 | } 28 | ``` 29 | 30 | **css after:** 31 | ```css 32 | .red { 33 | color: red; 34 | } 35 | ``` 36 | 37 | ### How? 38 | 39 | The HTML files are loaded by [jsdom](https://github.com/tmpvar/jsdom) and JavaScript is executed. UnCSS filters out selectors that are not found in the HTML files. 40 | 41 | See the [UnCSS](https://github.com/uncss/uncss) docs for more information. 42 | 43 | ## Installation 44 | 45 | postcss-uncss specifies UnCSS as a [peerDependency](https://docs.npmjs.com/files/package.json#peerdependencies), so you will have to install UnCSS as well. 46 | 47 | ```bash 48 | npm install postcss-uncss uncss 49 | ``` 50 | 51 | postcss-uncss' MAJOR & MINOR version numbers correspond to UnCSS' version numbers; however, the PATCH version number may differ. 52 | 53 | ## Usage 54 | 55 | ```js 56 | postcss([ require('postcss-uncss') ]) 57 | ``` 58 | 59 | See [PostCSS](https://github.com/postcss/postcss) docs for examples for your environment. 60 | 61 | ## Options 62 | 63 | - **html** (Array): provide a list of html files to parse for selectors and elements. Usage of [globs](https://github.com/isaacs/node-glob) is allowed. 64 | 65 | - **ignore** (Array): provide a list of selectors that should not be removed by UnCSS. For example, styles added by user interaction with the page (hover, click), since those are not detectable by UnCSS yet. Both literal names and regex patterns are recognized. Otherwise, you can add a comment before specific selectors in your css: 66 | 67 | ```css 68 | /* uncss:ignore */ 69 | .selector1 { 70 | /* this rule will be ignored */ 71 | } 72 | 73 | .selector2 { 74 | /* this will NOT be ignored */ 75 | } 76 | ``` 77 | 78 | ### Example Configuration 79 | 80 | ```js 81 | { 82 | html: ['index.html', 'about.html', 'team/*.html'], 83 | ignore: ['.fade'] 84 | } 85 | ``` 86 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports=require('uncss').postcssPlugin; 3 | } catch (e) { 4 | console.error('An error was encountered in postcss-uncss; do you have uncss installed as a dependency?'); 5 | console.error(e); 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-uncss", 3 | "version": "0.17.0", 4 | "description": "Use uncss as a postcss plugin", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/uncss/postcss-uncss.git" 12 | }, 13 | "keywords": [ 14 | "postcss-plugin", 15 | "uncss" 16 | ], 17 | "author": "Ryan Zimmerman (http://ryanzim.com/)", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/uncss/postcss-uncss/issues" 21 | }, 22 | "homepage": "https://github.com/uncss/postcss-uncss#readme", 23 | "peerDependencies": { 24 | "uncss": "^0.17.0" 25 | } 26 | } 27 | --------------------------------------------------------------------------------