Skip to content

Commit

Permalink
Merge pull request #1673 from lihbr/fix/purge-enabled-false-eval-to-true
Browse files Browse the repository at this point in the history
Fix `purgeEnabled` evaluating to true when `config.purge.enabled` is false
  • Loading branch information
adamwathan committed Apr 30, 2020
2 parents e52c59a + ddc6e1d commit 67ec21e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 24 additions & 0 deletions __tests__/purgeUnusedStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ test('does not purge if the array is empty', () => {
})
})

test('does not purge if explicitly disabled', () => {
const OLD_NODE_ENV = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')

return postcss([
tailwind({
...defaultConfig,
purge: { enabled: false },
}),
])
.process(input, { from: inputPath })
.then(result => {
process.env.NODE_ENV = OLD_NODE_ENV
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
'utf8'
)

expect(result.css).toBe(expected)
})
})

test('purges outside of production if explicitly enabled', () => {
const OLD_NODE_ENV = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
Expand Down
8 changes: 5 additions & 3 deletions src/lib/purgeUnusedStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function removeTailwindComments(css) {
}

export default function purgeUnusedUtilities(config) {
const purgeEnabled =
_.get(config, 'purge.enabled', false) === true ||
(config.purge !== undefined && process.env.NODE_ENV === 'production')
const purgeEnabled = _.get(
config,
'purge.enabled',
config.purge !== undefined && process.env.NODE_ENV === 'production'
)

if (!purgeEnabled) {
return removeTailwindComments
Expand Down

0 comments on commit 67ec21e

Please sign in to comment.