Giter Site home page Giter Site logo

simonwep / vite-plugin-optimize-css-modules Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 3.0 48 KB

πŸ—œ Mangle / minimize css module classnames in production like facebook and Google do!

JavaScript 18.09% TypeScript 81.91%
css-minify css-modules vite vite-plugin css plugin

vite-plugin-optimize-css-modules's Introduction


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 */
}

vite-plugin-optimize-css-modules's People

Contributors

asherjingkongchen avatar simonwep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vite-plugin-optimize-css-modules's Issues

What about caching?

One of the advantages of vite's SHAs is that they remain unchanged if the file contents remain unchanged after building the project. This means that no matter how many times you build and deploy, users will not have to re-download files that they have in their cache already.

On the other hand this means that using your plugin, users might not re-download certain files that could have changed if they have them cached already since the identifier (the css class name) did not change as well.
Am I mistaken in that?

Why not use base36?

Please forgive my silly question.

Is there a reason why you don’t simply do index.toString(36) instead of what you are doing now with your createCounter function?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.