Skip to content

Commit 3bccabb

Browse files
committed
Support for referencing nested theme keys
1 parent 38079b4 commit 3bccabb

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
lines changed

__tests__/fixtures/purge-example-dynamic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body id="tailwind">
77
<main>
8-
<div class="bg-{colors} {screens}:flex bg-red-500 md:bg-blue-300 w-1/2"></div>
8+
<div class="bg-red-{colors.red} {screens}:flex bg-red-500 md:bg-blue-300 w-1/2"></div>
99
</main>
1010
</body>
1111
</html>

__tests__/purgeUnusedStyles.test.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,24 +367,6 @@ test('dynamic classes can be used safely using class hints', () => {
367367
expect(result.css).toContain('.bg-red-700')
368368
expect(result.css).toContain('.bg-red-800')
369369
expect(result.css).toContain('.bg-red-900')
370-
expect(result.css).toContain('.bg-blue-100')
371-
expect(result.css).toContain('.bg-blue-200')
372-
expect(result.css).toContain('.bg-blue-300')
373-
expect(result.css).toContain('.bg-blue-400')
374-
expect(result.css).toContain('.bg-blue-500')
375-
expect(result.css).toContain('.bg-blue-600')
376-
expect(result.css).toContain('.bg-blue-700')
377-
expect(result.css).toContain('.bg-blue-800')
378-
expect(result.css).toContain('.bg-blue-900')
379-
expect(result.css).toContain('.bg-yellow-100')
380-
expect(result.css).toContain('.bg-yellow-200')
381-
expect(result.css).toContain('.bg-yellow-300')
382-
expect(result.css).toContain('.bg-yellow-400')
383-
expect(result.css).toContain('.bg-yellow-500')
384-
expect(result.css).toContain('.bg-yellow-600')
385-
expect(result.css).toContain('.bg-yellow-700')
386-
expect(result.css).toContain('.bg-yellow-800')
387-
expect(result.css).toContain('.bg-yellow-900')
388370

389371
expect(result.css).toContain('.flex')
390372
expect(result.css).toContain('.sm\\:flex')

src/lib/purgeUnusedStyles.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22
import postcss from 'postcss'
33
import purgecss from '@fullhuman/postcss-purgecss'
44
import log from '../util/log'
5-
import flattenColorPalette from '../util/flattenColorPalette'
65

76
function removeTailwindMarkers(css) {
87
css.walkAtRules('tailwind', rule => rule.remove())
@@ -99,7 +98,9 @@ export default function purgeUnusedUtilities(config, configChanged) {
9998
})
10099
}
101100

102-
const dynamicMatches = flattenThemeKeys(config.theme[themeKey])
101+
const dynamicMatches = flattenThemeKeys(
102+
_.get(config, ['theme', ...themeKey.split('.')], [])
103+
)
103104
.map(key => {
104105
return className.replace(`{${themeKey}}`, key)
105106
})

0 commit comments

Comments
 (0)