使用TailwindCSS将PurgeCSS白名单模式 [英] PurgeCSS whitelist patterns with TailwindCSS

查看:152
本文介绍了使用TailwindCSS将PurgeCSS白名单模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当通过PurgeCSS处理时,我试图保留所有TailwindCSS颜色类(即bg-绿色,bg-红色,text-green,text-red).这些颜色类别是在CMS中设置的,而不是在代码中设置的,因此我们无法在其中搜索代码,因为它们不存在(全部).

I am trying to preserve all TailwindCSS colour classes (i.e bg-green, bg-red, text-green, text-red) when it is processed via PurgeCSS. These colour classes are set in the CMS rather than code so we cannot search the code for them as they don't (all) exist here.

因此,我想使用PurgeCSS的白名单功能保留所有以"bg-"或"text-"开头的类.但是,我下面的模式似乎并没有解决问题?有什么想法可以调整吗?

Therefore I want to use the whitelisting feature of PurgeCSS to retain all classes that beging with 'bg-' or 'text-'. However, the pattern I have below doesn't seem to be doing the trick? Any ideas how to tweak it?

whitelistPatterns: ['^bg\-', '^text\-'],

推荐答案

问题似乎只是使用regexp,而不是字符串.

The issue appears to be simply to use regexp, not a string.

whitelistPatterns: [/^bg-/, /^text-/], // Retain all classes starting with...

这篇关于使用TailwindCSS将PurgeCSS白名单模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆