A Vite plugin that exports CSS variable values (defined via `:export` pseudo-class) to JavaScript, enabling sharing of design tokens between CSS/SCSS/LESS and JS. Current stable version is 3.1.0, compatible with Vite 5–8 and Node >=20.19.0 (or >=22.12.0). Key differentiators: support for nested `:export` rules that produce nested JS objects, works with CSS pre-processors (Sass, Less, Stylus) and CSS Modules, and ships TypeScript declarations. Releases follow semver; v3.0.0 dropped Vite 4 support and requires ESM.
npm install vite-plugin-css-exportVerified import paths — ran on the pinned version, not inferred.
Minimal Vite config with plugin, a CSS file exporting variables, and TS import using `?export` query to retrieve object.
Upgrade Vite to v5 or later, or pin to v2.x for Vite 4.
Convert to ESM (use `import` or set `"type": "module"` in package.json).
Do not nest `:export` inside at-rules; use CSS custom properties evaluated at runtime if dynamic queries needed.
Import both: import classes from './styles.module.css' and exportedData from './styles.module.css?export'.
Use `sharedData: 'cssExportedData'` instead of `sharedDataExportName: 'cssExportedData'`.
Switch to ESM: rename file to .mts or set `"type": "module"` in package.json, then use `import ViteCSSExportPlugin from 'vite-plugin-css-export'`.
Use default import: `import ViteCSSExportPlugin from 'vite-plugin-css-export'`.
Append `?export` to the import path: `import data from './styles.css?export'`.