Skip to content

vite, compiler: Add cssFileFilter option to customize VE module detection - #1773

Open
o-alexandrov wants to merge 1 commit into
vanilla-extract-css:masterfrom
o-alexandrov:custom-css-file-filter
Open

vite, compiler: Add cssFileFilter option to customize VE module detection#1773
o-alexandrov wants to merge 1 commit into
vanilla-extract-css:masterfrom
o-alexandrov:custom-css-file-filter

Conversation

@o-alexandrov

@o-alexandrov o-alexandrov commented Jul 18, 2026

Copy link
Copy Markdown

Summary

Adds an optional cssFileFilter option to vanillaExtractPlugin (@vanilla-extract/vite-plugin) and createCompiler (@vanilla-extract/compiler) so consumers can customize which files are treated as Vanilla Extract modules.

Today the filter is a hardcoded const in @vanilla-extract/integration:

export const cssFileFilter = /\.css\.(js|cjs|mjs|jsx|ts|tsx)(\?used)?$/;

It's imported directly by the Vite plugin and the compiler, with no way to override it. The new option threads a caller-provided RegExp through both, defaulting to the existing filter so nothing changes when it's omitted.

vanillaExtractPlugin({
  // e.g. treat `css.ts` as the VE module convention instead of `*.css.ts`
  cssFileFilter: /(?:^|[/\\])css\.(js|cjs|mjs|jsx|ts|tsx)(\?used)?$/,
});

Motivation

We use a single-filename convention (css.ts) rather than the *.css.ts suffix across a large codebase. With no public way to change the filter, our only option has been to patch @vanilla-extract/integration on disk after every install (rewriting the regex), which is fragile: a missed copy in a multi-repo/workspace setup silently leaves css.ts files untransformed, which surfaces later as Styles were unable to be assigned to a file at runtime. A first-class option removes the need for that patch.

Changes

  • @vanilla-extract/vite-plugin: new cssFileFilter?: RegExp option; used in the transform gate and HMR invalidation, and passed to createCompiler.
  • @vanilla-extract/compiler: new cssFileFilter?: RegExp on CreateCompilerOptions; used by the module scanner and the internal file-scope transform.
  • Both default to the existing cssFileFilter, so it's fully backwards compatible.
  • Added a compiler unit test with a .vanilla.ts fixture that is only recognized via a custom filter, plus a changeset (minor for both packages).

Notes

I've read the contributing guide's note that non-trivial changes are ideally discussed first: happy to move this to a discussion/issue if preferred. The change is small, additive, and non-breaking, so I've opened it as a PR to make the proposal concrete. Existing unit tests pass and the changed files are Prettier/oxlint clean.

…tion

The file filter used to detect Vanilla Extract modules was hardcoded to *.css.ts in @vanilla-extract/integration and imported by the Vite plugin and compiler with no way to override it. Expose a cssFileFilter option on vanillaExtractPlugin and createCompiler so a different naming convention (e.g. css.ts) can be used. Defaults to the existing filter, so behaviour is unchanged when omitted.
@changeset-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e14133

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@vanilla-extract/vite-plugin Minor
@vanilla-extract/compiler Minor
@vanilla-extract/turbopack-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another 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