mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Only log purge notice once per process
This commit is contained in:
parent
ef149cfafb
commit
2d090feb98
@ -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))
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
22
src/util/log.js
Normal 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)
|
||||
})
|
||||
},
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user