Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tailwind CSS: add pattern for important classnames to safelist

Is it possible to create safelist based on pattern with normal and important classnames, similar like we can add variants?

For example tailwind.config.js

module.exports = {
  content: [
    './pages/**/*.{html,js}',
    './components/**/*.{html,js}',
  ],
  safelist: [
    'text-2xl',
    'text-3xl',
    {
      pattern: /bg-(red|green|blue)-(100|200|300)/,
      variants: ['!'], // IT DOES NOT WORK
    },
  ],
  // ...
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is possible. The exclamation mark prefix would be part of the pattern:

{
  pattern: /^!?bg-(red|green|blue)-(100|200|300)$/,
}

This would produce both bg-red-100 as well as !bg-red-100, et al. See it working in this Tailwind Play (open the Generated CSS panel to see the results).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading