Skip to content

Conversation

@flex-jonghyen
Copy link

@flex-jonghyen flex-jonghyen commented Oct 24, 2025

Problem

The Vite plugin currently processes all .css.{ts,js,tsx,jsx} files based solely on file extension, without distinguishing between source files and already-compiled output.

This causes issues in monorepo setups where:

  1. Package A (e.g., design system) builds its vanilla-extract files
  2. Package B (e.g., application) imports from Package A
  3. Vite plugin tries to reprocess the already-compiled files from Package A's
  4. This fails because the VE compiler cannot process already-compiled files

Solution

Add a simple check in the transform hook to detect already-compiled vanilla-extract files by looking for the signature pattern: import statements containing .vanilla.css

Key pattern:

// Compiled file (should skip)
import './button.css.ts.vanilla.css';

or 

import './button.css.ts.vanilla-somehash.css'

Why Not Other Approaches?

Path-Based Filtering

Q: Since the Vite plugin has access to A's file path during build, why not filter based on path?

A: Path-based filtering would block use-cases where someone intentionally want to transpile Package A's source code during Package B's build (e.g., in monorepo development mode with direct source imports).

Content-based detection only skips files that are already compiled, preserving flexibility for different monorepo workflows.

Renaming Output Files (as suggested in #1568)

Q: Why not use rollup's assetFileNames option to rename compiled files (e.g., .styles.mjs instead of .css.mjs) to avoid the .css.{js,ts} pattern matching?

A: While this workaround can avoid the immediate issue, it doesn't address the root cause: the plugin attempting to reprocess already-compiled files.

This PR aims to fix the fundamental problem rather than working around it.

The file renaming approach remains valid as a temporary workaround, but this fix ensures the plugin correctly handles all scenarios by default.

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

⚠️ No Changeset found

Latest commit: 26ad448

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant