content key replaces purge in Tailwind CSS v3 with deprecation warning
0 reputation · 31 Aug 2022, 05:16 UTC
0 reputation · 31 Aug 2022, 05:16 UTC
Tailwind CSS v3 introduced the content configuration key to replace the legacy purge key, with the old key still accepted but emitting a deprecation warning ahead of removal in a future major release.
A migration plan needs to move file globs and safelist entries from purge to content while maintaining consistent class generation across builds. The configuration transition is complicated by backward compatibility that falls back to purge when content is absent, and by the relocation of safelist under content.
There is uncertainty about the interaction when both keys are present during a gradual change.
Does Tailwind merge the globs from content and purge or prioritize one source? Are safelist entries defined under the legacy purge key still honored after the move? What configuration shape avoids duplicate scanning while keeping the deprecation warning clear during transition?
33775 reputation · 31 Aug 2022, 08:41 UTC
In Tailwind CSS v3, the content configuration key replaces the legacy purge key. When both keys are present in tailwind.config.js, Tailwind prioritizes the content key and ignores the purge key for class generation. They are not merged.
Safelist entries defined under the legacy purge key are not honored once you move to v3. To ensure classes are preserved, you must relocate all safelist entries to content.safelist. Any safelist configuration remaining under purge will be ignored and will trigger a deprecation warning.
To avoid duplicate scanning while keeping the deprecation warning visible as a migration reminder, you should move all active globs and safelists to content and leave the purge key empty. This prevents the engine from processing the same files twice while maintaining the terminal alert.
module.exports = {
content: {
// 1. Move all file globs here
paths: ['./src/**/*.{html,js,ts,jsx,tsx}'],
// 2. Move safelist entries here
safelist: ['bg-red-500', 'text-center'],
},
// Keep this empty to maintain the deprecation warning
purge: [],
}
To verify your configuration is working correctly without duplicate processing:
npx tailwindcss -o build.css).content globs and content.safelist are present.purge key entirely to confirm the warning disappears without affecting the generated styles.This behavior applies to Tailwind CSS v3.x. In very early v3 releases, some users reported spurious warnings regarding duplicate scanning if globs overlapped between both keys; however, the engine still prioritized content. The safest approach across all v3 versions is to keep purge empty or removed.
Diagnostic Detail: Are you using a custom PostCSS plugin that specifically looks for the purge key? If so, moving to content may require updating that plugin's configuration separately.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.