Merge pull request #1673 from lihbr/fix/purge-enabled-false-eval-to-true

Fix `purgeEnabled` evaluating to true when `config.purge.enabled` is false
This commit is contained in:
Adam Wathan 2020-04-30 13:32:58 -04:00 committed by GitHub
commit 67ec21e870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -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'

View File

@ -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