TailwindCSS / PurgeCSS extractor string removing some classes

Viewed 3754

fairly new to Tailwind and PostCSS/PurgeCSS, so hoping this is a fairly simple fix.

In my tailwind.config.js, I am extending some of the spacing values, including adding a 0.5 value to align with the default Tailwind spacing scale. My file looks like this (extract):

module.exports = {
    important: false,
    theme: {
        spacing: {
            '0.5': '0.125rem',
        },
    },
}

I'm then using PostCSS to compile my CSS, which looks as follows, as you can see I'm using a bunch of plugins which work great:

module.exports = {
    parser: 'postcss-scss',
    plugins: [
        require('postcss-import'),
        require('postcss-nested'),
        require('postcss-responsive-type'),
        require('tailwindcss'),
        require('autoprefixer'),
        require('cssnano'),
    ]
}

Up to this point, all working great! However, I want to purge the css to remove all of the unused utility classes that Tailwind creates. This effects my postcss file as follows:

module.exports = {
    parser: 'postcss-scss',
    plugins: [
        require('postcss-import'),
        require('postcss-nested'),
        require('postcss-responsive-type'),
        require('tailwindcss'),
        require('autoprefixer'),
        require('@fullhuman/postcss-purgecss')({
            content: [
                './*.php',
                './**/*.php',
            ],
            defaultExtractor: content => content.match(/[\w-:/]+(?<!:)/g) || []
        }),
        require('cssnano'),
    ]
}

This is the point at which I lose some styles, specifically the specially configued Tailwind ones such as .h-0.5.

I siuspect the issue is within the defaultExtractor line?

defaultExtractor: content => content.match(/[\w-:/]+(?<!:)/g) || []

Anyone able to lend a hand? Thanks

2 Answers

Solved! It was, as expected, very simple. I was simply missing the '.' for the defaultExtractor:

defaultExtractor: content => content.match(/[\w-:./]+(?<!:)/g) || []
defaultExtractor: (content) => content.match(/[\w-:./]+(?<!:)/g) || [],

Fixed it

Related