Only log purge notice once per process

This commit is contained in:
Adam Wathan 2020-08-19 10:56:51 -04:00
parent ef149cfafb
commit 2d090feb98
4 changed files with 36 additions and 47 deletions

View File

@ -1,5 +1,6 @@
import _ from 'lodash'
import chalk from 'chalk'
import log from './util/log'
const featureFlags = {
future: ['removeDeprecatedGapUtilities'],
@ -57,27 +58,6 @@ export function issueFlagNotices(config) {
return
}
const log = {
info(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.cyan('info'), '-', message)
})
},
warn(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.yellow('warn'), '-', message)
})
},
risk(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.magenta('risk'), '-', message)
})
},
}
if (futureFlagsEnabled(config).length > 0) {
const changes = futureFlagsEnabled(config)
.map(s => chalk.cyan(s))

View File

@ -1,9 +1,7 @@
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'
import log from '../util/log'
function removeTailwindMarkers(css) {
css.walkAtRules('tailwind', rule => rule.remove())
@ -21,7 +19,7 @@ function removeTailwindMarkers(css) {
})
}
export default function purgeUnusedUtilities(config) {
export default function purgeUnusedUtilities(config, configChanged) {
const purgeEnabled = _.get(
config,
'purge.enabled',
@ -34,21 +32,14 @@ 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) {
log()
log(
emoji.warning,
chalk.yellow(
' Tailwind is not purging unused styles because no template paths have been provided.'
)
)
log(
chalk.white(
' If you have manually configured PurgeCSS outside of Tailwind or are deliberately not\n removing unused styles, set `purge: false` in your Tailwind config file to silence\n this warning.'
)
)
log(
chalk.white('\n https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css')
)
if (configChanged) {
log.warn([
'Tailwind is not purging unused styles because no template paths have been provided.',
'If you have manually configured PurgeCSS outside of Tailwind or are deliberately not removing unused styles, set `purge: false` in your Tailwind config file to silence this warning.',
'https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css',
])
}
return removeTailwindMarkers
}

View File

@ -18,7 +18,6 @@ import { issueFlagNotices } from './featureFlags.js'
import hash from 'object-hash'
let flagsIssued = null
let previousConfig = null
let processedPlugins = null
let getProcessedPlugins = null
@ -29,12 +28,9 @@ export default function(getConfig) {
const configChanged = hash(previousConfig) !== hash(config)
previousConfig = config
if (!flagsIssued || !_.isEqual(flagsIssued, _.pick(config, ['future', 'experimental']))) {
flagsIssued = _.pick(config, ['future', 'experimental'])
issueFlagNotices(config)
}
if (configChanged) {
issueFlagNotices(config)
processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
getProcessedPlugins = function() {
return {
@ -55,7 +51,7 @@ export default function(getConfig) {
substituteScreenAtRules(config),
substituteClassApplyAtRules(config, getProcessedPlugins, configChanged),
applyImportantConfiguration(config),
purgeUnusedStyles(config),
purgeUnusedStyles(config, configChanged),
]).process(css, { from: _.get(css, 'source.input.file') })
}
}

22
src/util/log.js Normal file
View File

@ -0,0 +1,22 @@
import chalk from 'chalk'
export default {
info(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.cyan('info'), '-', message)
})
},
warn(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.yellow('warn'), '-', message)
})
},
risk(messages) {
console.log('')
messages.forEach(message => {
console.log(chalk.bold.magenta('risk'), '-', message)
})
},
}