# Gulp(opens new window)

# Installation

npm i -D gulp-purgecss
npm install --save-dev gulp-purgecss
1
2

# Usage

By default, purgecss outputs the source CSS with unused selectors removed:

const gulp = require('gulp')
const purgecss = require('gulp-purgecss')

gulp.task('purgecss', () => {
    return gulp.src('src/**/*.css')
        .pipe(purgecss({
            content: ['src/**/*.html']
        }))
        .pipe(gulp.dest('build/css'))
})
1
2
3
4
5
6
7
8
9
10

By setting the rejected option, you can 'invert' the output to list only the removed selectors:

const gulp = require('gulp')
const rename = require('gulp-rename')
const purgecss = require('gulp-purgecss')

gulp.task('purgecss-rejected', () => {
    return gulp.src('src/**/*.css')
        .pipe(rename({
            suffix: '.rejected'
        })
        .pipe(purgecss({
            content: ['src/**/*.html'],
            rejected: true
        }))
        .pipe(gulp.dest('build/css'))
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15