Skip to content

When I specify extractors, I want to specify only the extractors I want to override #148

Description

@ahus1

Describe the current behavior

When specifying an extractor specific for one file type, but no extractor for the other file types in the project, I get an exception "Cannot read property 'extractor' of undefined"

To Reproduce

  1. use html and js as content
  2. add an extractor for html, but not js
  3. run purgecss
  4. see error

Expected behavior

I want the default extract to be used for any file type that I don't specify. Apparently this happened to other people previously as well: #95

Desktop (please complete the following information):

  • OS: Windows (but shouldn't be related)
  • Version of Purgecss: 1.1.0

Additional context

Suggested fix: in getFileExtractor() the DefaultExtractor should be returned when extractorObj is undefined

purgecss/src/index.js

Lines 230 to 237 in 9b637bd

getFileExtractor(filename: string, extractors: Array<ExtractorsObj> = []) {
if (!extractors.length) return DefaultExtractor
const extractorObj: any = extractors.find(extractor =>
extractor.extensions.find(ext => filename.endsWith(ext))
)
return extractorObj.extractor
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions