Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to local-css to prefix minified classnames #3484

Open
mpech opened this issue Nov 10, 2023 · 8 comments
Open

add option to local-css to prefix minified classnames #3484

mpech opened this issue Nov 10, 2023 · 8 comments
Labels

Comments

@mpech
Copy link

mpech commented Nov 10, 2023

link of original issue which was resolved: #3295

our main concern is avoiding classname conflict accross lib built separately

Our problem is the following

  • we have library A bundled by esbuild
  • client B which depends on library A, also bundled after by esbuild
    => when B builds, B's stylesheet clashes with A's stylesheet, because we do not specify A as entrypoint, we just get the built files from A

What we would appreciate

  • enable customizing classname like 'A[classnamehash]' (this would be the best, we could prefix our classes by libraryname)
  • either specify A's stylesheet when building B to esbuild (it may be impractical, because if B is actually not a client but a library too, and if B uses A as peerdeps, while bundling B we will avoid clashes from A, but when building the client, maybe the classnames generated of A will have changed by then, which forces to have strict versionning)
@mhsdesign
Copy link

Yes i agree. I currently have encountered the same problem. Im building a javascript problem and it seems that another plugin already uses esbuild which causes css classes to overlap randomly. A simple prefix like my-vendor would be perfect.

lightningcss also allows to declare a prefix via their "pattern" option: https://lightningcss.dev/css-modules.html#custom-naming-patterns

@zouloux
Copy link

zouloux commented Nov 28, 2023

Hi, this is also an issue on some projects here.
I didn't find a way to intercept renaming through a plugin.
If anybody has a temporary solution, it would be helpful. In the meanwhile, we will disable the minify option.

@mhsdesign
Copy link

You can use another plugin for css modules - like mine ^^ https://github.com/mhsdesign/esbuild-plugin-lightningcss-modules its based on lightningcss

@markplindsay
Copy link

@evanw, my team develops a browser extension, and I recently switched us to esbuild for the dramatic speed improvement. Thank you very much for writing this software.

Our extension coexists in the DOM on many websites, and it is subject to these sites' global styling. I was troubleshooting a visual bug this week, and I noticed that Reddit uses a classname simply named .a. (Perhaps it is even generated by esbuild.)

Unfortunately, this conflicts with an .a classname generated by our esbuild during local-css's minification process, and it messes up our extension's styling when it is rendered on Reddit.

We're currently working around this by not minifying our extension, but introducing an optional prefix for generated local-css classnames as configuration would solve this problem for us 100%.

@evanw evanw added the css label May 25, 2024
@kachurun
Copy link

I have the same problem. I'm creating a powerful HTML element for my website builder, and every single HTML element has its own bundle. Now, when two or more elements with CSS modules are involved, it causes this issue.

@chowey
Copy link

chowey commented Sep 10, 2024

I just have a site with pre-existing CSS. Someone in the distant past decided to use a short class name. Now it conflicts with the minified class names from esbuild.

So I'd also like to see an option in esbuild to prefix class names.

@chowey
Copy link

chowey commented Sep 16, 2024

I took a stab at this with #3914. It's working for me locally.

I called the new setting local-css-prefix.

@ziemkowski
Copy link

#3914 would be helpful.

Using CSS Modules with Rollup/LightningCSS has encouraged the team to go back to using simple class names like .btn, .contianer, .link, .row, etc., which are defined in most CSS framework out there and collide if esbuild-generated local CSS classnames can't be made unique via prefix or hash.

Unfortunately, the CSS Module plugins I've tried so far to get around this break down with splitting: true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants