Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Add rejected functionality, and update readme with Usage example. #19

Merged
merged 3 commits into from Apr 29, 2019

Conversation

michaelrog
Copy link
Contributor

@michaelrog michaelrog commented Apr 8, 2019

When its rejected option is set, purgecss makes available the list of removed selectors.

This PR defines gulp-purgecss's response to that same option. When the rejected option is set, the plugin outputs a list of the removed selectors, rather than the default output.

It's extremely useful for the developer to sanity-check the list of rejected selectors, both to aid in identifying obsolete CSS that could be pruned from source files, and to discover any dynamically generated selector patterns that need to be whitelisted.

Importantly, this "inverted" output is still valid CSS: The list is formatted with empty declaration blocks for each selector in the list, so it will not cause errors when used as part of a Gulp process that still expects gulp-purgecss to output valid CSS (such as the new example provided in the README):

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'))
})

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

(p.s. This feature was also requested for the postcss-purgecss plugin. I'll be happy to PR it there also, if you approve.)

@vervelover
Copy link

thank you for this, I implemented your changes locally and it's working perfectly!

@Ffloriel
Copy link
Member

Thanks for the PR!

@Ffloriel Ffloriel merged commit ae06717 into FullHuman:master Apr 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants