Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind safelist patterns for multiple patterns?

Tags:

tailwind-css

I'm trying to use safelist patterns (formerly whitelist patterns) with Tailwind CSS V3.1.6 and have the following. It's not working, but essentially I'm trying to safelist all values beginning with bg-, text- and border-

safelist: [
  // Retain all classes starting with...,
  {
    pattern: /bg-/,
    pattern: /text-/,
    pattern: /border-/,
  },
],
like image 436
dungey_140 Avatar asked May 08 '26 17:05

dungey_140


2 Answers

You can safelist multiple entrances within an array of objects like

safelist: [
  {pattern: /bg-./},
  {pattern: /text-./},
  {pattern: /border-./},
]

but in your case it would be shorter to use pipe sign "|"

safelist: [
  {pattern: /(bg|text|border)-./}
]

More about safelisting with regular expressions can be found here

like image 73
Ihar Aliakseyenka Avatar answered May 10 '26 07:05

Ihar Aliakseyenka


Or if you want with any pattern just one liner

      pattern: /([a-zA-Z]+)-./,
like image 29
Marius Avatar answered May 10 '26 05:05

Marius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!