├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── LICENSE ├── README.md ├── gulpfile.js ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | ./dest -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 4, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true 20 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Addy Osmani 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | gulp-uncss-task (deprecated) 2 | =============== 3 | 4 | **Note:** this module is deprecated in favor of [gulp-uncss](https://github.com/ben-eb/gulp-uncss). 5 | 6 | > A Gulp task for removing unused CSS 7 | 8 | This is a Gulp compliment to `grunt-uncss`. 9 | 10 | *Issues with the output should be reported on the [UnCSS](https://github.com/giakki/uncss/issues) issue tracker.* 11 | 12 | ## Install 13 | 14 | Install with [npm](https://npmjs.org/package/gulp-uncss-task) 15 | 16 | ``` 17 | npm install --save-dev gulp-uncss-task 18 | ``` 19 | 20 | ## Usage 21 | 22 | ```js 23 | var gulp = require('gulp'); 24 | var uncss = require('gulp-uncss-task'); 25 | 26 | gulp.task('default', function() { 27 | gulp.src('bootstrap.css') 28 | .pipe(uncss({ 29 | html: ['index.html', 'contact.html', 'about.html'] 30 | })) 31 | .pipe(gulp.dest('dest')); 32 | }); 33 | ``` 34 | 35 | ## Options 36 | 37 | Sample use of all supported options: 38 | 39 | ``` 40 | ignore: ['#added_at_runtime', /test\-[0-9]+/], 41 | csspath: "../public/css/", 42 | raw: 'h1 { color: green }', 43 | stylesheets: ["lib/bootstrap/dist/css/bootstrap.css", "src/public/css/main.css"], 44 | timeout: 1000 45 | ``` 46 | 47 | ### What do the options do? 48 | 49 | - __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. 50 | - __csspath__ [String]: Path where the CSS files are related to the html files. By default, UnCSS uses the path specified in the `` 51 | - __stylesheets__ [Array]: Force the list of stylesheets to optimize using a path relative to the `gulpfile.js`. Otherwise, it extracts the stylesheets from the html files. 52 | - __raw__ [String]: Give the task a raw string of CSS in addition to the existing stylesheet options; useful in scripting when your CSS hasn't yet been written to disk. 53 | - __timeout__ [Number]: Specify how long to wait for the JS to be loaded. 54 | 55 | ## License 56 | 57 | MIT © [Addy Osmani](http://addyosmani.com) 58 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uncss = require('gulp-uncss-task'); 3 | 4 | gulp.task('default', function() { 5 | gulp.src('bootstrap.css') 6 | .pipe(uncss({ 7 | html: ['index.html', 'contact.html', 'about.html'] 8 | })) 9 | .pipe(gulp.dest('dest')); 10 | }); 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var es = require('event-stream'); 3 | var uncss = require('uncss'); 4 | 5 | module.exports = function() { 6 | var args = arguments; 7 | var input = args[0].html; 8 | var options = {}; 9 | 10 | options.csspath = args[0].csspath; 11 | options.stylesheets = args[0].stylesheets; 12 | options.ignore = args[0].ignore; 13 | options.timeout = args[0].timeout; 14 | 15 | return es.map(function(file, cb){ 16 | options.raw = String(file.contents); 17 | uncss(input, options, function(output){ 18 | file.contents = new Buffer(output); 19 | cb(null, file); 20 | }); 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-uncss-task", 3 | "version": "0.3.0", 4 | "description": "A Gulp task for removing unused CSS", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/addyosmani/gulp-uncss-task" 12 | }, 13 | "keywords": [ 14 | "uncss", 15 | "unused", 16 | "css", 17 | "gulpplugin" 18 | ], 19 | "dependencies": { 20 | "event-stream": "~3.1.0", 21 | "gulp-util": "~2.2.14", 22 | "uncss": "~0.8.0" 23 | }, 24 | "devDependencies": { 25 | "mocha": "*", 26 | "gulp": "~3.5.6" 27 | }, 28 | "author": { 29 | "name": "Addy Osmani", 30 | "email": "addyosmani@gmail.com", 31 | "url": "http://addyosmani.com" 32 | }, 33 | "scripts": { 34 | "test": "mocha" 35 | }, 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/addyosmani/gulp-uncss-task/issues" 39 | }, 40 | "homepage": "https://github.com/addyosmani/gulp-uncss-task" 41 | } 42 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var gutil = require('gulp-util'); 4 | var uncss = require('./index'); 5 | 6 | var html = '