css-typed-vars weekly downloads statistics
By StanislavKozachenko · npm · Webpack plugins
Generate TypeScript typed constants from CSS custom properties
css-typed-vars has 790 recorded weekly downloads on npm, an increase of 1134% over the past 30 days, ranking #2144 of 3,247 tracked listings.
About css-typed-vars
- Installation
- Two approaches
- CLI
- Plugin
- Usage
- Programmatic API
- Supported formats
- @property syntax typing
- Contributing
var(--color-primary) is just a string. Rename the variable — the error shows up only in the browser.
css-typed-vars scans your CSS files and gives you typed constants. Use cssVars.colorPrimary instead — TypeScript catches missing variables at compile time.
Each generated key also carries a /** @default ... */ comment with the property's declared CSS value, so your editor shows it on hover and autocomplete. A value written over several lines (a font stack, a list of shadows) is joined into one. If the variable is registered with @property, its syntax descriptor shows up too, and an enum-like syntax (e.g. "light | dark | system") gets its own exported TS union type.
Installation
npm install -D css-typed-vars
Requires Node.js 20.19+ or 22.12+.
Two approaches
| CLI | Plugin | |
|---|---|---|
| How it works | Generates cssVars.ts in your project | Virtual module, no file generated |
| Import | import { cssVars } from './cssVars' | import { cssVars } from 'css-typed-vars/vars' |
| Watch | --watch flag | vite dev, browser reloads automatically |
| Works with | Everything | Vite, webpack, Rollup, esbuild (not Turbopack) |
CLI
Create a config file in your project root:
// css-typed-vars.config.js
export default {
input: 'src/styles/**/*.{css,scss}',
output: 'src/cssVars.ts',
};
Then run:
npx css-typed-vars # generate once
npx css-typed-vars --watch # watch for changes
Add to your package.json scripts:
{
"scripts": {
"generate:vars": "css-typed-vars",
"generate:vars:watch": "css-typed-vars --watch"
}
}
Given this CSS:
:root {
--color-primary: #3b82f6;
--spacing-md: 8px;
}
Generates src/cssVars.ts:
// generated — do not edit
export const cssVars = {
colorPrimary: 'var(--color-primary)',
spacingMd: 'var(--spacing-md)',
} as const;
export type CssVarName = keyof typeof cssVars;
CLI flags
npx css-typed-vars --input "src/styles/**/*.css" --output src/cssVars.ts
npx css-typed-vars --input "src/styles/**/*.{css,scss}" --output src/cssVars.ts --watch
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --exclude "**/vendor/**"
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prefix theme --naming snake
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.js # generates .js + .d.ts
npx css-typed-vars --input "src/**/*.css" --output tokens.json # W3C design tokens (DTCG) JSON
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --selector ".dark" --selector "[data-theme='dark']"
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --check # for CI: exits 1 if out of date
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --group # nest keys by first name segment
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune --usage "src/**/*.{ts,tsx}" # drop unused vars from the output
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check --usage "src/**/*.{ts,tsx}" # for CI: exits 1 if any var is unused
```…
Description from the npm listing.
- css
- scss
- less
- css-variables
- custom-properties
- typescript
- codegen
- typed
- vite-plugin
- unplugin
- webpack-plugin
- rollup-plugin
- esbuild-plugin
- design-tokens
- dtcg
- tailwindcss
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (142)Similar npm Webpack plugins plugins
All 20 css-typed-vars alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/css-typed-vars. First seen Nov 13, 2026; last successful collection Dec 6, 2026. See the methodology.