0

I'm trying to figure out how to implement a custom regex pattern for purging my tailwind project. The issue is that I am not using HTML elements at all, rather, I have created a PHP framework package that uses PHP functions to build HTML.

Here is an example of the PHP code I need purging:

public function view(View $v)
{
    return $v->section(
        $v->h1('Dashboard)->class('text-xl p-4'),
        $v->p('You are logged in!')->class('p-4')
    )->class('border divide-y md:w-1/2 mx-auto');
}

Here is my current tailwind config file:

module.exports = {
    purge: [
        './app/Components/**/*..php',
    ],
    darkMode: false, // or 'media' or 'class'
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [
        require('@tailwindcss/forms'),
    ],
}

As you can see, I've set the purge path to my components folder, which contains all of my PHP classes.

The problem is tailwing is purging EVERYTHING. I can't figure out how to add a custom regex pattern so it will not purge items inside of the ->class() methods.

How would I implement a purge regex pattern so I don't lose the classes used within these ->class() methods?

kjdion84
  • 9,552
  • 8
  • 60
  • 87
  • 1
    My guess is that you have extra dot in your file - it should be './app/Components/**/*.php'. Bit if you're interseted in more configuration including extractor regex try to use this - https://purgecss.com/configuration.html#configuration-file . I've tested your method in my php-project, Tailwind extract exactly these classes - text-xl, p-4, etc. – Ihar Aliakseyenka Jan 21 '21 at 09:48
  • I’m so dumb. Thank you. – kjdion84 Jan 21 '21 at 12:05

0 Answers0