vite-plugin-optimize-css-modules
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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 of v3 or greater. It only makes sense to use if you're using css modules.

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

In your vite.config.ts simply add the plugin:

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:

@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":

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

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

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

Package Sidebar

Install

npm i vite-plugin-optimize-css-modules

Weekly Downloads

893

Version

1.0.6

License

MIT

Unpacked Size

6.72 kB

Total Files

6

Last publish

Collaborators

  • simonwep