Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/Simonwep/vite-plugin-optimize-css-modules

🗜 Mangle / minimize css module classnames in production like facebook and Google do!
https://github.com/Simonwep/vite-plugin-optimize-css-modules

css css-minify css-modules plugin vite vite-plugin

Last synced: about 1 month ago
JSON representation

🗜 Mangle / minimize css module classnames in production like facebook and Google do!

Lists

README

        



Vite Plugin - Optimize CSS Modules


Mangle classnames in production - save up to 20% on css for free!


CI Status
Install count
Current version
Support me

### Setup

This plugin requires [vite](https://vitejs.dev/) of v3 or greater.
It only makes sense to use if you're using [css modules](https://vitejs.dev/config/shared-options.html#css-modules).

```sh
$ npm install --save-dev vite-plugin-optimize-css-modules
```

In your [`vite.config.ts`](https://vitejs.dev/config/#configuring-vite) simply add the plugin:

```ts
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [
optimizeCssModules()
]
})
```

And that's it. When running `vite build` your generated CSS should be significantly smaller.

### How does it work?

By default, when using css modules, you end up with hashes or other long class-names in your bundled css files:

```css
@keyframes _close-card_pzatx_1 {
/* ...css */
}

._card_pzatx_32 {
/* ...css */
}

._back_pzatx_49 ._content_pzatx_70 ._close_pzatx_74 {
/* ...css */
}
```

By using this module, the smalles possible classname will be used for each "id":

```css
@keyframes a {
/* ...css */
}

.v {
/* ...css */
}

.c .s .w {
/* ...css */
}
```