FullHuman / postcss-purgecss

PostCSS plugin for purgecss
MIT License
91 stars 5 forks source link

feat(content-options): Allow content option to be specified as function that is evaluated per input source file #50

Closed sod closed 4 years ago

sod commented 4 years ago

Hey, love your addon 👍. We use it at rebuy.de for our angular application.

I'd like to be able to specify the content option as a function - in a fully backwards compatible way of course - see the added part in the README.md:

--

content (required)

Type: (sourceInputFile: string) => Array<string>

content may be a function that returns the array of globs. The function receives the current source input file. With this you may provide a specific array of globs for each input. E.g. for an angular application only scan the components template counterpart for every component scss file:

purgecss({
  content: (source: string) => {
    (/component\.scss$/.test(source))
      ? [sourceInputFile.replace(/scss$/, 'html')]
      : ['./src/**/*.html']
  },
})

--

In our case this would be:

  1. faster (100ms instead of currently 20 sec.) - we right now have 125 components with 125 scss entry files
  2. more accurate, as the specific globs will only use the tokens from the related template
sod commented 4 years ago

should i fork/publish or reopen the pr in the new repo?

Ffloriel commented 4 years ago

If you could reopen the pr in the main repo, it would be perfect. I'll create an issue for this in the main repo too.