Skip to content

Commit ab52a8c

Browse files
committed
Support purge: false, add more info to console warning
1 parent e8c0264 commit ab52a8c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

__tests__/purgeUnusedStyles.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ test('does not purge if explicitly disabled', () => {
173173
})
174174
})
175175

176+
test('does not purge if purge is simply false', () => {
177+
const OLD_NODE_ENV = process.env.NODE_ENV
178+
process.env.NODE_ENV = 'production'
179+
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
180+
const input = fs.readFileSync(inputPath, 'utf8')
181+
182+
return postcss([
183+
tailwind({
184+
...defaultConfig,
185+
purge: false,
186+
}),
187+
])
188+
.process(input, { from: inputPath })
189+
.then(result => {
190+
process.env.NODE_ENV = OLD_NODE_ENV
191+
const expected = fs.readFileSync(
192+
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
193+
'utf8'
194+
)
195+
196+
expect(result.css).toBe(expected)
197+
})
198+
})
199+
176200
test('purges outside of production if explicitly enabled', () => {
177201
const OLD_NODE_ENV = process.env.NODE_ENV
178202
process.env.NODE_ENV = 'development'

src/cli/emoji.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const no = get('no_entry_sign')
55
export const go = get('rocket')
66
export const pack = get('package')
77
export const disk = get('floppy_disk')
8+
export const warning = get('warning')

src/lib/purgeUnusedStyles.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import _ from 'lodash'
22
import postcss from 'postcss'
33
import purgecss from '@fullhuman/postcss-purgecss'
4+
import chalk from 'chalk'
5+
import { log } from '../cli/utils'
6+
import * as emoji from '../cli/emoji'
47

58
function removeTailwindComments(css) {
69
css.walkComments(comment => {
@@ -23,7 +26,7 @@ export default function purgeUnusedUtilities(config) {
2326
const purgeEnabled = _.get(
2427
config,
2528
'purge.enabled',
26-
config.purge !== undefined && process.env.NODE_ENV === 'production'
29+
config.purge !== false && config.purge !== undefined && process.env.NODE_ENV === 'production'
2730
)
2831

2932
if (!purgeEnabled) {
@@ -32,7 +35,9 @@ export default function purgeUnusedUtilities(config) {
3235

3336
// Skip if `purge: []` since that's part of the default config
3437
if (Array.isArray(config.purge) && config.purge.length === 0) {
35-
console.log('Skipping purge because no template paths provided...')
38+
log()
39+
log(emoji.warning, chalk.yellow(' Skipping purge because no template paths provided.'))
40+
log(chalk.white(' To silence this warning, set `purge: false` in your Tailwind config file.'))
3641
return removeTailwindComments
3742
}
3843

0 commit comments

Comments
 (0)