Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ function registerPlugins(plugins, context) {
: [util]

for (let util of utils) {
for (let { pattern, variants = [] } of checks) {
for (let { pattern, variants = [], opacities = [] } of checks) {
// RegExp with the /g flag are stateful, so let's reset the last
// index pointer to reset the state.
pattern.lastIndex = 0
Expand All @@ -722,6 +722,18 @@ function registerPlugins(plugins, context) {
content: variant + context.tailwindConfig.separator + util,
extension: 'html',
})
for (let opacity of opacities) {
context.changedContent.push({
content: variant + context.tailwindConfig.separator + util + '/' + opacity,
extension: 'html',
})
}
}
for (let opacity of opacities) {
context.changedContent.push({
content: util + '/' + opacity,
extension: 'html',
})
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/safelist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ it('should safelist based on a pattern regex', () => {
{
pattern: /bg-(red)-(100|200)/,
variants: ['hover'],
opacities: ['50'],
},
],
}
Expand All @@ -64,11 +65,19 @@ it('should safelist based on a pattern regex', () => {
background-color: rgb(254 226 226 / var(--tw-bg-opacity));
}

.bg-red-100\/50 {
background-color: rgb(254 226 226 / 0.5);
}

.bg-red-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 202 202 / var(--tw-bg-opacity));
}

.bg-red-200\/50 {
background-color: rgb(254 202 202 / 0.5);
}

.uppercase {
text-transform: uppercase;
}
Expand All @@ -78,10 +87,18 @@ it('should safelist based on a pattern regex', () => {
background-color: rgb(254 226 226 / var(--tw-bg-opacity));
}

.hover\:bg-red-100\/50:hover {
background-color: rgb(254 226 226 / 0.5);
}

.hover\:bg-red-200:hover {
--tw-bg-opacity: 1;
background-color: rgb(254 202 202 / var(--tw-bg-opacity));
}

.hover\:bg-red-200\/50:hover {
background-color: rgb(254 202 202 / 0.5);
}
`)
})
})
Expand Down