Vite plugin that purges unused Tailwind CSS classes from the production bundle. Current stable version is 0.3.5, released with regular patches. The plugin targets only Tailwind-specific classes (not all CSS) and works with Tailwind v3 and component libraries like Skeleton, Flowbite, or shadcn-ui. It analyzes the Vite module graph to extract used selectors and passes them to PurgeCSS, reducing CSS size significantly (e.g., from 105 kB to 16 kB for a Skeleton template). Since v0.3.0, the default behavior is focused on Tailwind classes only, with an optional legacy mode for broader purging. Note: Tailwind v4 will make this plugin obsolete.
npm install vite-plugin-tailwind-purgecssVerified import paths — ran on the pinned version, not inferred.
Shows how to add the purgeCss plugin to a SvelteKit project with Vite configuration using TypeScript.
If you need the old behavior (purge all unused CSS), enable legacy mode: purgeCss({ legacy: true }).Ensure tailwindcss@^3.3.0 is installed in your project.
Check the new type definition for PurgeOptions; for legacy mode use { legacy: true }.If you need broader purging, enable legacy mode or use a separate CSS purging tool.
Plan to migrate to Tailwind v4 when it is stable and remove this plugin.
Install tailwindcss: npm install -D tailwindcss@^3.3.0
Use named import: import { purgeCss } from 'vite-plugin-tailwind-purgecss'Use `const { purgeCss } = require('vite-plugin-tailwind-purgecss')` or `import { purgeCss } from 'vite-plugin-tailwind-purgecss'`.