Skip to content

Forcing a CSS definition inclusion even when no pages use that definition #2708

Discussion options

You must be logged in to vote

Hey!

You can use the whitelist option in the purge section of your Tailwind config to achieve that - add the class name(s) you want to preserve even if not present in any of the templates, and they will be skipped by purge!

// tailwind.config.js
module.exports = {
  purge: {
    content: ['./src/**/*.html'],

    // These options are passed through directly to PurgeCSS
+   options: {
+     whitelist: ['bg-red-500', 'px-4', 'any-class-you-want-to-keep'],
+   }
  },
  // ...
}

Important note: Tailwind 2.0, which ships in ~2 weeks, updates to PurgeCSS 3, which will lead to a change in this option: the whitelist option will become safelist, so when you upgrade, you'll need to adjust stat in y…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ericjohncarlson
Comment options

Answer selected by ericjohncarlson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants