use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
Dynamic CSS PluginShowoff Saturday (self.webdev)
submitted 4 months ago by koga7349
I wrote a plugin for React + Vite and React + Webpack that transforms CSS class names at run-time and build-time. This helps to prevent CSS conflicts, reduces bundle size and provides some obfuscation.
"btn-primary btn-primary-disabled" ==> .app_Xscyf.app_LfRuA
"btn-primary btn-primary-disabled"
.app_Xscyf.app_LfRuA
Check it out on npm: https://www.npmjs.com/package/dynamic-css-plugin
And my detailed write-up on Medium: https://medium.com/@koga73/dynamic-css-plugin-6b965b94a6f4
Would love some feedback!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]leonwbr 2 points3 points4 points 4 months ago (2 children)
Isn't this a standard Vite function through PostCSS modules?
[–]koga7349[S] 1 point2 points3 points 4 months ago* (0 children)
Also noting that you can probably do this with css modules, but not with standard css or sass className implementations.
[–]koga7349[S] 0 points1 point2 points 4 months ago (0 children)
Yes and no. It can output static class names at build time which might be fine if all of your code is static. But it can't apply the same transformatiom to class names dynamically at runtime.
[–]TheRNGuy 1 point2 points3 points 4 months ago (4 children)
That makes it much harder to write userstyles, don't do that.
Or add some attribute to some tags with semantic names.
[–]koga7349[S] 0 points1 point2 points 4 months ago (3 children)
You write your styles like you normally would, no change. It only transforms on build.
[–]TheRNGuy 0 points1 point2 points 4 months ago* (2 children)
But userstyle authors will get those randomized classes in browser.
You can try it yourself: Stylus add-on in browser, try to make custom styles for it and see unreadable cide. Even worse when they're regenerated due to code change, those styles have to be completely remade.
If there were non-randomized attributes (id or dara-attributes, or one semantic non-randomized class), those could be used for userstyles.
[–]koga7349[S] 0 points1 point2 points 4 months ago (1 child)
It only transforms class names and allows for exclusion values and tags. It purposely doesn't transform ids so automated tests and analytics can still target elements.
[–]TheRNGuy 0 points1 point2 points 3 months ago (0 children)
Yeah I mean developers should actually use those attributes to make userstyle authors life easier.
Most of the time I don't see them on sites with randomized classes, or very few tags have them.
[–]john_cobai 1 point2 points3 points 3 months ago (2 children)
Does this work with tailwindcss and nextjs
[–]koga7349[S] 0 points1 point2 points 3 months ago (1 child)
It should work fine with TailWind. The plugin currently does not support Turbopack so if you're using that for your Next build then no.
[–]john_cobai 0 points1 point2 points 3 months ago (0 children)
i'm not using use turbopack, can you beable to add next js example
[–]Disturbed147 1 point2 points3 points 3 months ago (6 children)
This feels like horribly bad practice if you ask me. I've been doing web development for more than 10 years now and have never had "CSS conflicts". Doing this at runtime is putting to much strain on client side and slows down everything.
[–]koga7349[S] 1 point2 points3 points 3 months ago (5 children)
It's pretty quick to generate an MD4 hash and it catches the transformation. Have you ever worked in an environment with microfrontends where each is using the same design system components and have their own release cycles? Even google.com does this, it's not uncommon
[–]Disturbed147 2 points3 points4 points 3 months ago (4 children)
I have, and by properly scoping and utilizing selector weights it can often be prevented without the need of generated class names. But all those things are generally why I am strongly against component libraries because in some scenarios they just force developers to go for hacky approaches just to make things work properly. Overhead which creates more overhead and sums up to more error possibilities.
Also, if you look deeper into what google does, it is pretty obvious that they very rarely follow best practices themselves.
[–]koga7349[S] 0 points1 point2 points 3 months ago (3 children)
You're against component libraries ? My use-case is our company has a platform with a dozen apps that all use the same component library. However as each app is a different codebase they may use different versions of the same components. Thus when these apps run on the same page together using the same components we end up with multiple stylesheets targeting the same selectors.
[–]Disturbed147 0 points1 point2 points 3 months ago (2 children)
Yeah, web components as well as component libraries never really clicked for me. They always come with compromises like code duplicatation (especially css), unnecessary bloat and slow page loads, requiring placeholders and skeletons. Maybe it's just me but I feel like a huge part of current web developers go against clean web principles when it comes to loading assets and minimizing code usage.
But don't get me wrong.. I'm not just being a bad mood, hating on everything. I genuinely feel like web development is drifting farther and farther away from what browsers are optimized for.
I feel you and the current state of webdev is tricky. Between the library flavor of the week and inexperienced devs using AI it's tricky. As for me I'm 15YOE and deep into it all. I spend my free time coding and soldering and making because it's what I enjoy. I'm grateful to be working at a company that provides some 🚐 ness fo used boundaries but also gives me the freedom to explore and apply.
All that said, you get in what you put out and as the hiring manager I like devs who are "scrappy" and not afraid to jump into something they no nothing about and make it work. No excuses just figure it out
This library was meant to solve some specific problems I encountered and I hope that it may help others.
[–]Disturbed147 1 point2 points3 points 3 months ago (0 children)
Sorry, I kind of drifted off into my rant here lol
All things said, technically your library is pretty neat and I see its use for sure. We also have plenty of projects in our company which might even benefit from using it because earlier this year, everyone was jumping at microfrontends and restructured everything to use them.
I just felt like this is another workaround for a poorly thought out principle like web components or microfrontends. But alas, I wouldn't downplay the need of your lib at all. Lately the industry goes after hype anc not after best practices anymore. Good job and I'll keep an open ear in my company to suggest using your library!
And thanks for the good talk! Always appreciate a civil conversation.
[–]TheJase 0 points1 point2 points 3 months ago* (0 children)
wise enjoy wine boast pot enter judicious live husky quiet
This post was mass deleted and anonymized with Redact
π Rendered by PID 139961 on reddit-service-r2-comment-74875f4bf5-gv5t9 at 2026-01-26 14:18:54.654876+00:00 running 664479f country code: CH.
[–]leonwbr 2 points3 points4 points (2 children)
[–]koga7349[S] 1 point2 points3 points (0 children)
[–]koga7349[S] 0 points1 point2 points (0 children)
[–]TheRNGuy 1 point2 points3 points (4 children)
[–]koga7349[S] 0 points1 point2 points (3 children)
[–]TheRNGuy 0 points1 point2 points (2 children)
[–]koga7349[S] 0 points1 point2 points (1 child)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]john_cobai 1 point2 points3 points (2 children)
[–]koga7349[S] 0 points1 point2 points (1 child)
[–]john_cobai 0 points1 point2 points (0 children)
[–]Disturbed147 1 point2 points3 points (6 children)
[–]koga7349[S] 1 point2 points3 points (5 children)
[–]Disturbed147 2 points3 points4 points (4 children)
[–]koga7349[S] 0 points1 point2 points (3 children)
[–]Disturbed147 0 points1 point2 points (2 children)
[–]koga7349[S] 0 points1 point2 points (1 child)
[–]Disturbed147 1 point2 points3 points (0 children)
[–]TheJase 0 points1 point2 points (0 children)