Purgecss: [Question] How to tell purgecss to NOT scan a subfolder within the specified folder?

Created on 28 Nov 2018  路  1Comment  路  Source: FullHuman/purgecss

In a project structure where I have this:

  • source/

    • foo/

    • bar/

    • dontscan.ext

    • index.html

I specified this in the config folders: ['source'].

How do I configure the plugin to NOT scan for words in the bar directory?

Most helpful comment

The options for purgecss look like this:

{
  content: Array<string | RawContent>,
  css: Array<string | RawContent>,
  extractors?: Array<ExtractorsObj>,
  whitelist?: Array<string>,
  whitelistPatterns?: Array<RegExp>,
  whitelistPatternsChildren?: Array<RegExp>,
  keyframes?: boolean,
  fontFace?: boolean,
  rejected?: boolean
}

As you can see there is no option called folders.

If you want to scan all the content inside a given folder you need to pass a glob to the content option.

Here is an example:

content: [
    // keep only those that you need
    '**/*.html' // will look inside any folder for an .html file
    '!(bar)/**/*.html' // will look inside any folder that is not 'bar'
    '!({bar,foo})/**/*.html' // will look inside any folder that is nor 'bar' nor 'foo'
    '!(bar-*)/**/*.html' // will look inside any folder that does not start with 'bar-'
  ],
  css: [`**/*.css`],

>All comments

The options for purgecss look like this:

{
  content: Array<string | RawContent>,
  css: Array<string | RawContent>,
  extractors?: Array<ExtractorsObj>,
  whitelist?: Array<string>,
  whitelistPatterns?: Array<RegExp>,
  whitelistPatternsChildren?: Array<RegExp>,
  keyframes?: boolean,
  fontFace?: boolean,
  rejected?: boolean
}

As you can see there is no option called folders.

If you want to scan all the content inside a given folder you need to pass a glob to the content option.

Here is an example:

content: [
    // keep only those that you need
    '**/*.html' // will look inside any folder for an .html file
    '!(bar)/**/*.html' // will look inside any folder that is not 'bar'
    '!({bar,foo})/**/*.html' // will look inside any folder that is nor 'bar' nor 'foo'
    '!(bar-*)/**/*.html' // will look inside any folder that does not start with 'bar-'
  ],
  css: [`**/*.css`],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

maartenvanbenthem picture maartenvanbenthem  路  4Comments

simllll picture simllll  路  3Comments

JounQin picture JounQin  路  8Comments

joneldiablo picture joneldiablo  路  6Comments

simplenotezy picture simplenotezy  路  3Comments