Allow users to block generation of certain utilities (#9812)

* Add blocklist tests

* Build initial implementation of blocklist

* wip

* wip

* wip

* Update changelog
This commit is contained in:
Jordan Pittman 2022-11-11 11:47:20 -05:00 • committed by GitHub
parent 4ccc0fa12a
commit 602101d030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 1 deletions

View file

@ -1165,7 +1165,8 @@ export function createContext(tailwindConfig, changedContent = [], root = postcs
candidateRuleCache: new Map(),
classCache: new Map(),
applyClassCache: new Map(),
notClassCache: new Set(),
// Seed the not class cache with the blocklist (which is only strings)
notClassCache: new Set(tailwindConfig.blocklist ?? []),
postCssNodeCache: new Map(),
candidateRuleMap: new Map(),
tailwindConfig,

View file

@ -150,6 +150,24 @@ export function normalizeConfig(config) {
return []
})()
// Normalize the `blocklist`
config.blocklist = (() => {
let { blocklist } = config
if (Array.isArray(blocklist)) {
if (blocklist.every((item) => typeof item === 'string')) {
return blocklist
}
log.warn('blocklist-invalid', [
'The `blocklist` option must be an array of strings.',
'https://tailwindcss.com/docs/content-configuration#discarding-classes',
])
}
return []
})()
// Normalize prefix option
if (typeof config.prefix === 'function') {
log.warn('prefix-function', [