Skip to content

Commit 67ec21e

Browse files
authored
Merge pull request #1673 from lihbr/fix/purge-enabled-false-eval-to-true
Fix `purgeEnabled` evaluating to true when `config.purge.enabled` is false
2 parents e52c59a + ddc6e1d commit 67ec21e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

__tests__/purgeUnusedStyles.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ test('does not purge if the array is empty', () => {
149149
})
150150
})
151151

152+
test('does not purge if explicitly disabled', () => {
153+
const OLD_NODE_ENV = process.env.NODE_ENV
154+
process.env.NODE_ENV = 'production'
155+
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
156+
const input = fs.readFileSync(inputPath, 'utf8')
157+
158+
return postcss([
159+
tailwind({
160+
...defaultConfig,
161+
purge: { enabled: false },
162+
}),
163+
])
164+
.process(input, { from: inputPath })
165+
.then(result => {
166+
process.env.NODE_ENV = OLD_NODE_ENV
167+
const expected = fs.readFileSync(
168+
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
169+
'utf8'
170+
)
171+
172+
expect(result.css).toBe(expected)
173+
})
174+
})
175+
152176
test('purges outside of production if explicitly enabled', () => {
153177
const OLD_NODE_ENV = process.env.NODE_ENV
154178
process.env.NODE_ENV = 'development'

src/lib/purgeUnusedStyles.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ function removeTailwindComments(css) {
2020
}
2121

2222
export default function purgeUnusedUtilities(config) {
23-
const purgeEnabled =
24-
_.get(config, 'purge.enabled', false) === true ||
25-
(config.purge !== undefined && process.env.NODE_ENV === 'production')
23+
const purgeEnabled = _.get(
24+
config,
25+
'purge.enabled',
26+
config.purge !== undefined && process.env.NODE_ENV === 'production'
27+
)
2628

2729
if (!purgeEnabled) {
2830
return removeTailwindComments

0 commit comments

Comments
 (0)