Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for overriding the default extractor #183

Merged
merged 1 commit into from Apr 20, 2019
Merged

Add support for overriding the default extractor #183

merged 1 commit into from Apr 20, 2019

Conversation

adamwathan
Copy link
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
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.

None yet

2 participants