Skip to content

Add support for overriding the default extractor - #183

Merged
Ffloriel merged 1 commit into
FullHuman:masterfrom
adamwathan:override-default-extractor
Apr 20, 2019
Merged

Add support for overriding the default extractor#183
Ffloriel merged 1 commit into
FullHuman:masterfrom
adamwathan:override-default-extractor

Conversation

@adamwathan

Copy link
Copy Markdown
Contributor

Proposed changes

This PR implements the ability override the default extractor as proposed in #180.

It allows the user to set the default extractor using a new defaultExtractor option that accepts either a class or a function:

// Using a class
new Purgecss({
    content: [`${root}special_characters/special_characters.js`],
    css: [`${root}special_characters/special_characters.css`],
    defaultExtractor: class {
        static extract(content) {
            return content.match(/[A-z0-9-:/]+/g)
        }
    }
})

// Using a function
new Purgecss({
    content: [`${root}special_characters/special_characters.js`],
    css: [`${root}special_characters/special_characters.css`],
    defaultExtractor: content => content.match(/[A-z0-9-:/]+/g),
})

This simplifies configuration if the end user wants to use a custom extractor for everything, as they don't have to provide a list of matching extensions. It also helps to avoid issues where the user wants to use a custom extractor for everything, but forgets to update the extension list after introducing a new file type to the project. Since Purgecss is often only run in production builds, this can help reduce end-user mistakes that cause bugs in production that weren't detected in development.

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)

@Ffloriel
Ffloriel merged commit 0dfb5de into FullHuman:master Apr 20, 2019
@Ffloriel

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants