Skip to content

[v4] Unused variables and classes in the output when using Vite #16532

@rozsazoltan

Description

@rozsazoltan

I came across a question on StackOverflow that I didn’t understand at first, as I had a similar issue up until v4.0.4 with CLI and PostCSS, but v4.0.5 fixed it, and I verified that it works in v4.0.6 as well.

However, when I create a new Vite project, for example, with Svelte or Vue, the build results include unused variables and classes, so in a simple empty project, I get a 22.53kb result instead of the expected file size, which is the Preflight (4kb?).

The .gitignore by default excludes the mapping of node_modules, so I assume TailwindCSS doesn't pull variables from there. There isn't a single TailwindCSS class used in the project, and still, a lot of unnecessary content is getting into dist/css/index.css.

The problem is, of course, resolved with PurgeCSS, but the real question is why unused variables (e.g., all colors, ...) and class names (e.g., .shadow, .capitalize, .lowercase) are included in the output by default.

Versions

"dependencies": {
  "@tailwindcss/vite": "^4.0.6",
  "tailwindcss": "^4.0.6",
  "vue": "^3.5.13"
},
"devDependencies": {
  "@vitejs/plugin-vue": "^5.2.1",
  "@vue/tsconfig": "^0.7.0",
  "typescript": "~5.7.3",
  "vite": "^6.1.0",
  "vue-tsc": "^2.2.0"
}

Reproduction steps

  • Vite create-app
  • TailwindCSS v4 with Vite installation steps
  • pnpm build

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions