question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practice to compress css selector names?

See original GitHub issue

What problem does this feature solve?

Hello. First, thank you for working on this useful tool.

My story: I tried to find information how to implement css selector name compression to reduce size of bundle, but I found only this article, which seems bit outdated: https://medium.com/@my_own_grave/reducing-css-generated-by-vue-loader-by-using-classnames-shorten-trick-aa1d25d77473

Is there a good solution for this task nowadays, or maybe someone solved it without monkey-patching css-loader? If it is solved somehow, I would like to see any example. I think, it would be great if vue-cli can provide such functionality.

Thanks in advance.

What does the proposed API look like?

I suggest to add some option to vue.config.js that will enable css class name compresion, such as: compressCssClassNames: true

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
LinusBorgcommented, Apr 25, 2019
  1. That only works with CSS modules
  2. The vue-loader specific restriction mentioned in the article no longer applies.
  3. People likely have many different opinions about what that id should look like.

You can simply add your own getLocalIdent function to the css loader options like this:

module.exports = {
  css: {
    loaderOptions: {
      css: {
        getLocalIdentName() => ...
        // or just:
		localIdentName: '[hash:6]'

      }
    }
  }
}
0reactions
georgyfarnievcommented, Apr 25, 2019

@LinusBorg thank you. Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The complete best practices for minifying CSS - LogRocket Blog
Minifying CSS files is more nuanced than you might think at first. Learn the various minification tools, how to determine and remove unused ......
Read more >
Before deployment, is there tool to compress HTML class ...
This will minify all CSS selectors in HTML, JS and CSS files (actually any file you want). I saved 20ish% of the CSS...
Read more >
Reducing CSS bundle size 70% by cutting the class names ...
There is one thing a minifier cannot do – change the selector names. This is because a CSS minifier does not control the...
Read more >
How I Reduced My CSS Bundle Size By More Than 20%
Generating the short names. The next step is to actually generate the valid minified selectors for use. First we define the ...
Read more >
10 Best Practices for Quickly Improving Your CSS - Webtips
CSS has its own nuances that can make or break your design. Here are 10 tips for CSS : best practices that can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found