Skip to content

Vite: classes are detected from the whole project instead of the cssEntryFile directory (differs from Metro) #747

Closed as not planned

Description

@SalvadorLekan

What happened?

On Vite, Tailwind generates classes found anywhere in the project, not only in the directory of cssEntryFile.

On Metro, compileTailwind.ts#L16-L25 scans **/* from path.dirname(cssPath), which matches the behaviour described in #133 (cssEntryFile marks the app root, and @source adds anything outside it). On Vite, uniwind leaves compilation to @tailwindcss/vite, which scans from the Vite root. The same CSS entry therefore produces different stylesheets on the two bundlers.

In our app (cssEntryFile: './src/global.css') the Vite stylesheet had 182 more rules than the Metro web export, about 2.8 KB gzipped. They came from Markdown docs, SVGs and previous build output in the project root. We excluded them with @source not rules. @import 'tailwindcss' source('./') would be the direct fix, but uniwind cannot parse it (separate issue: #746).

Steps to Reproduce

  1. Clone the repository below. It is apps/vite-example plus docs/notes.md, which is outside src/, not imported, and contains className="bg-red-500 animate-spin"
  2. bun install
  3. bun run build
  4. grep -oE '\.(bg-red-500|animate-spin)' dist/assets/*.css prints .animate-spin and .bg-red-500, although neither is used in src/

Snack or Repository Link

https://github.com/SalvadorLekan/uniwind-vite-scan-root-repro

Uniwind version

1.13.0

React Native Version

0.88.0

Platforms

Web

Expo

No

Additional information 〰

Activity

  1. Brentlok commented on Oct 26, 2026

    @Brentlok
    Contributor

    This is expected behaviour, not something Uniwind controls. On Vite, Tailwind compilation is handled entirely by @tailwindcss/vite, which scans for class candidates from the Vite project root. That's standard Tailwind v4 behaviour, and you'd get the same result without Uniwind. On Vite, cssEntryFile is only used to collect theme variables for the generated uniwind.css. It doesn't affect where Tailwind looks for classes.

    This failed before because of #746, which is fixed in #752 and will ship in the next release. Until then, the @source not rules you're already using are a good workaround.

  2. added
    wontfixThis will not be worked on
    and removed on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions