diff --git a/src/featureFlags.js b/src/featureFlags.js index b5d4da489..7140eff4d 100644 --- a/src/featureFlags.js +++ b/src/featureFlags.js @@ -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)) diff --git a/src/lib/purgeUnusedStyles.js b/src/lib/purgeUnusedStyles.js index 296715b48..8058ce1df 100644 --- a/src/lib/purgeUnusedStyles.js +++ b/src/lib/purgeUnusedStyles.js @@ -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 } diff --git a/src/processTailwindFeatures.js b/src/processTailwindFeatures.js index c3e809219..c6a388e84 100644 --- a/src/processTailwindFeatures.js +++ b/src/processTailwindFeatures.js @@ -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') }) } } diff --git a/src/util/log.js b/src/util/log.js new file mode 100644 index 000000000..f2f3d8ace --- /dev/null +++ b/src/util/log.js @@ -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) + }) + }, +}