A Vite plugin that minifies CSS modules classnames in production builds by replacing long generated hashes with the shortest possible identifiers (a, b, c, ...). v1.4.0, actively maintained, supports Vite v2–v8. Reduces CSS file size by up to 30% and build time by up to 94% (benchmarked on Bootstrap and Materialize). Ships TypeScript types. Alternative to generic CSS minifiers because it targets classname mangling specifically for CSS modules, preserving functionality while maximizing compression.
npm install vite-plugin-optimize-css-modulesVerified import paths — ran on the pinned version, not inferred.
Add the Vite plugin to your config. No options needed; works out of the box.
Ensure your CSS files use the `.module.css` extension or configure Vite's `css.modules` option properly.
This is by design. No action needed, but be aware that production CSS differs from dev CSS.
Update Vite to v2, v3, v4, v5, v6, v7, or v8. Check package.json for exact peer range.
Use static class references from CSS modules (e.g., `styles.card`) rather than constructing them from strings.
Change to: import { optimizeCssModules } from 'vite-plugin-optimize-css-modules'Install Vite v2–v8: npm install vite@^5.0.0 (or matching your project's needs)
Add `optimizeCssModules()` to the `plugins` array in `vite.config.ts` and ensure your CSS file is named like `styles.module.css`.