Support purge: false, add more info to console warning

This commit is contained in:
Adam Wathan 2020-05-01 08:25:45 -04:00
parent e8c0264898
commit ab52a8c082
3 changed files with 32 additions and 2 deletions

View File

@ -173,6 +173,30 @@ test('does not purge if explicitly disabled', () => {
})
})
test('does not purge if purge is simply false', () => {
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: 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

@ -5,3 +5,4 @@ export const no = get('no_entry_sign')
export const go = get('rocket')
export const pack = get('package')
export const disk = get('floppy_disk')
export const warning = get('warning')

View File

@ -1,6 +1,9 @@
import _ from 'lodash'
import postcss from 'postcss'
import purgecss from '@fullhuman/postcss-purgecss'
import chalk from 'chalk'
import { log } from '../cli/utils'
import * as emoji from '../cli/emoji'
function removeTailwindComments(css) {
css.walkComments(comment => {
@ -23,7 +26,7 @@ export default function purgeUnusedUtilities(config) {
const purgeEnabled = _.get(
config,
'purge.enabled',
config.purge !== undefined && process.env.NODE_ENV === 'production'
config.purge !== false && config.purge !== undefined && process.env.NODE_ENV === 'production'
)
if (!purgeEnabled) {
@ -32,7 +35,9 @@ export default function purgeUnusedUtilities(config) {
// Skip if `purge: []` since that's part of the default config
if (Array.isArray(config.purge) && config.purge.length === 0) {
console.log('Skipping purge because no template paths provided...')
log()
log(emoji.warning, chalk.yellow(' Skipping purge because no template paths provided.'))
log(chalk.white(' To silence this warning, set `purge: false` in your Tailwind config file.'))
return removeTailwindComments
}