mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Don't purge components, don't purge if paths empty, add empty purge to config stub
This commit is contained in:
parent
3a53a8c858
commit
77d3f7590e
@ -68,6 +68,51 @@ test('purges unused classes', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('does not purge components', () => {
|
||||
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({
|
||||
...config,
|
||||
purge: [path.resolve(`${__dirname}/fixtures/**/*.html`)],
|
||||
}),
|
||||
])
|
||||
.process(input, { from: inputPath })
|
||||
.then(result => {
|
||||
process.env.NODE_ENV = OLD_NODE_ENV
|
||||
|
||||
expect(result.css).toContain('.container')
|
||||
|
||||
expect(result.css).not.toContain('.bg-red-600')
|
||||
expect(result.css).not.toContain('.w-1\\/3')
|
||||
expect(result.css).not.toContain('.flex')
|
||||
expect(result.css).not.toContain('.font-sans')
|
||||
expect(result.css).not.toContain('.text-right')
|
||||
expect(result.css).not.toContain('.px-4')
|
||||
expect(result.css).not.toContain('.h-full')
|
||||
|
||||
expect(result.css).toContain('.bg-red-500')
|
||||
expect(result.css).toContain('.md\\:bg-blue-300')
|
||||
expect(result.css).toContain('.w-1\\/2')
|
||||
expect(result.css).toContain('.block')
|
||||
expect(result.css).toContain('.md\\:flow-root')
|
||||
expect(result.css).toContain('.h-screen')
|
||||
expect(result.css).toContain('.min-h-\\(screen-4\\)')
|
||||
expect(result.css).toContain('.bg-black\\!')
|
||||
expect(result.css).toContain('.font-\\%\\#\\$\\@')
|
||||
expect(result.css).toContain('.w-\\(1\\/2\\+8\\)')
|
||||
expect(result.css).toContain('.inline-grid')
|
||||
expect(result.css).toContain('.grid-cols-3')
|
||||
expect(result.css).toContain('.px-1\\.5')
|
||||
expect(result.css).toContain('.col-span-2')
|
||||
expect(result.css).toContain('.col-span-1')
|
||||
expect(result.css).toContain('.text-center')
|
||||
})
|
||||
})
|
||||
|
||||
test('does not purge except in production', () => {
|
||||
const OLD_NODE_ENV = process.env.NODE_ENV
|
||||
process.env.NODE_ENV = 'development'
|
||||
@ -92,6 +137,30 @@ test('does not purge except in production', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('does not purge if the array is empty', () => {
|
||||
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: [],
|
||||
}),
|
||||
])
|
||||
.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'
|
||||
|
||||
@ -28,6 +28,12 @@ export default function purgeUnusedUtilities(config) {
|
||||
return removeTailwindComments
|
||||
}
|
||||
|
||||
// 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...')
|
||||
return removeTailwindComments
|
||||
}
|
||||
|
||||
return postcss([
|
||||
function(css) {
|
||||
const mode = _.get(config, 'purge.mode', 'conservative')
|
||||
@ -38,12 +44,10 @@ export default function purgeUnusedUtilities(config) {
|
||||
|
||||
css.walkComments(comment => {
|
||||
switch (comment.text.trim()) {
|
||||
case 'tailwind start components':
|
||||
case 'tailwind start utilities':
|
||||
case 'tailwind start screens':
|
||||
comment.text = 'purgecss end ignore'
|
||||
break
|
||||
case 'tailwind end components':
|
||||
case 'tailwind end utilities':
|
||||
case 'tailwind end screens':
|
||||
comment.text = 'purgecss start ignore'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
purge: [],
|
||||
prefix: '',
|
||||
important: false,
|
||||
separator: ':',
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
purge: [],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user