r/reactjs • u/CaptainOnBoard • Aug 23 '20
Resource A CLI tool that scans your project and splits the one big global CSS file into component level css files.
46
u/ftfymf Aug 23 '20
Nice, how does it handle rules used in multiple components? Does it repeat them in each component css file?
27
u/CaptainOnBoard Aug 23 '20
For now, yes.
I created this when I was working on codebase that had huge css files and it would have taken weeks to make it modular considering the size.
I haven't put much time into it, but if people really want that stuff I might work on it a bit more seriously.
6
u/DasBeasto Aug 23 '20
Does it handle nested css well? Very cool idea! I’m still looking for a good tool to strip out unused CSS rules if you want a next project!
8
5
u/tandrewnichols Aug 23 '20
You want PurgeCSS. It generates a CSS bundle from only the styles used in your application. There's a PostCSS plugin for it, so you can do autoprefixing and minification the same time.
2
u/flurpandzurp Aug 23 '20
Is this a problem nowadays, though? Sweet tool though, regardless
11
u/tandrewnichols Aug 23 '20
At large companies with old code bases? 100% a problem still.
3
u/swyx Aug 23 '20
i mean. i worked at a company with 3 frontend devs and a 4ish year old codebase. was already a problem. i think just age alone will do it regardless of team size.
1
u/tandrewnichols Aug 23 '20
Yeah, definitely a problem outside big companies with old code bases too. That's just the easiest example to point to. Honestly, I'm curious now where u/flurpandzurp worked that it WASN'T a problem.
1
1
1
2
u/leodriesch Aug 23 '20 edited Aug 23 '20
Sorry for off-topic, but how can you put the terminal in the bottom left corner in VSCode?
Edit: Apparently you can just drag the terminal tab to the sidebar and it just works.
1
u/Attack_Bovines Aug 23 '20
Bring up your command palette ctrl (or cmd on macOS) + shift + p, then type “Terminal”. You want “Terminal: Create New Integrated Terminal”. The keyboard shortcut should show on the right side of the command palette result list item.
1
u/DVGY Aug 23 '20
This is pro level stuff, how can i implement a library which read jsx files and output className attributes values
1
u/abudabu Aug 23 '20
Nice. Does it infer what bits of the CSS to extract by analyzing an HTML file? Does it accept jsx files? What does "exclude" do? This would be good material for the README.
0
u/all-i-know-is-code Aug 23 '20
This is super cool - I’m doing exactly this by hand but for my Vue project at work 😭 wish I could use this but great work
-1
u/fuzulus Aug 23 '20
This is cool and I will definitely try it, but I'm interested if you can parse .html.twig files also?
2
u/CaptainOnBoard Aug 23 '20
I haven't had a chance to work on twig so I dont know how they look but it should work on any file that has html like syntax(start tags and closing tags)
1
u/fuzulus Aug 23 '20
Yeah, makes sense, but it wouldn't work in most cases then, which is okay. There are a few workarounds possible, awesome tool either way. :)
2
Aug 23 '20
[removed] — view removed comment
2
u/CaptainOnBoard Aug 23 '20
I haven't tried it
I created this when I was working on legacy codebase that had huge css files and it would have taken weeks to make it modular considering the size.
I haven't put much time into it, but if people really want that stuff I might work on it a bit more seriously.
20
u/CaptainOnBoard Aug 23 '20
As the title says, I made a CLI that takes in the path to the global css file and splits that into module level css files.
REPO : https://github.com/royalbhati/CSSplit