· 2 min read · updated
Open Props with postcss-jit-props in Vite
Installed open-props and postcss-jit-props as dev dependencies.
What we did
- Installed
open-propsandpostcss-jit-propsas dev dependencies. - Configured PostCSS inline in
vite.config.ts(css.postcss.plugins), not in apostcss.config.*file orpackage.json. - Added the CSS Variable Autocomplete extension, pointed at
node_modules/open-props/open-props.min.css, so the editor suggests Open Props variables.
What I learned
- A static site ships only
build/. Nothing fromnode_modulesruns in the browser, so for adapter-static everything is a dev dependency.dependenciesonly matters for libraries or server apps that runpnpm install --prod. - CSS has no tree-shaking.
@import "open-props/colors"copies every color into the bundle, and the minifier can't drop unused custom properties. JIT does that job: it reads my CSS and injects only thevar(--x)I use. - JIT only sees CSS. Variables used only in inline
styleattributes or in JS won't be injected. - I pass the whole
OpenPropsobject once. The plugin uses it as a lookup table, so I don't list variables by hand. - Svelte
<style>blocks go through Vite's CSS pipeline too, so one PostCSS config covers global CSS and components. css.postcss(PostCSS plugins) andplugins(Vite plugins) are different lists for different tools.- With an inline
css.postcss, Vite stops looking forpostcss.config.*files.
Problems & fixes
- No autocomplete for Open Props variables: with JIT they aren't defined in any CSS file in the project, so the editor had nothing to read. Fixed with the extension's
lookupFilessetting.
Links
Next
- Semantic tokens in
tokens.css.