martijnvreeken's avatar

Mix purges my dynamic classes

I have this piece of code in my L8 project:

<div class="mt-6 text-{{ $reseller_code }}-dark">
    {{ $header }}
</div>

Obviously, css-purger does not recognize the class and purges my text-mnp-dark tailwind class. How does one prevent this?

0 likes
6 replies
martijnvreeken's avatar

@Sinnbeck Cheers for the quick response! Appreciate it. I have that working, but than I have to compile my CSS code every time a new reseller is added to my database. I would like a more flexibel aproach. Any suggestions?

martijnvreeken's avatar

@Sinnbeck I have this:

    purge: {
        "content": [
        './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
        './storage/framework/views/*.php',
        './resources/views/**/*.blade.php',
        ],
        // These options are passed through directly to PurgeCSS
        options: {
            safelist: {
                standard: [/(mnp|fnz)/],
            }
        },
    },

mnp and fnz are reseller codes, more are to be added through a Reseller model. This would mean I need to run mix --production for each new reseller in the future.

Sinnbeck's avatar

@martijnvreeken A assume you also need to add them as colors in tailwind then?

Then dont use tailwind for those colors. Use the color codes saved in the database and set them using inline styles

martijnvreeken's avatar

@Sinnbeck You are right. And I'm an idiot ;) I will choose either of those solutions. Thanks for having a look with me.

Please or to participate in this conversation.