-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature request: css code transpiling #8
Comments
Nice, I like this idea! I've wanted to add it for a while now. A few questions:
Let me know your thoughts! |
@camertron So cool you like my proposal! //app/assets/stylesheets/ui/entries/home/index.css
@import url("../../united/colors.css");
@import url("../../united/images.css");
@import url("../../../../../components/ui/mix/home/space_home_component/space_home_component.css");
@import url("../../../../../components/ui/mix/home/spacecraft_list_component/spacecraft_list_component.css");
@import url("../../../../../components/ui/mix/home/spacecraft_item_component/spacecraft_item_component.css"); Next, esbuild makes bundling for each entrypoint by config which may looks like this: //package.json
"build:css": "esbuild app/assets/stylesheets/ui/entries/**/index.css --bundle --minify --outdir=app/assets/builds --outbase=app/assets/stylesheets --loader:.woff2=file --loader:.svg=file --external:app/assets/fonts/ui/* --external:app/assets/images/ui/*", Or sometimes i can bundle some components styles too, it may help if you for example uses rails-turbo (which i personally don't like and uses Birdel instead) About another gem - personally I more like including a module based on some config in project like And about hashes - you are right, it may 100% better to see normally named css classes like |
Ah ok so you add them manually for each component. I wonder if there's a way to automate that? It would also be really cool if the page only requested the CSS it actually needed based on the components that have been rendered. With regard to esbuild, propshaft, etc... it feels like automatic discovery of .css files might be hard to implement consistently for all these build systems. If the page only requests the component CSS it actually needs, maybe Sprockets would be the right build system to use.
I'm not sure what you mean, can you explain in more detail?
That's a good point... although as I said above, I think it makes more sense for the page to request individual CSS files per component rather than bundle all of them up into one giant CSS file. With HTTP/2, gzip, etc, I think per-component CSS files could be pretty small and wouldn't impact load times dramatically. |
Quick answear about <div class="ui--mix--home--spacecraft-item-component" data-controller="ui--mix--home--spacecraft-item-component">
<div class="ui--mix--home--spacecraft-item-component-wrapper" data-action="click->ui--mix--home--spacecraft-item-component#handleClick">
<div class="ui--mix--home--spacecraft-item-component-avatar">
</div>
<div class="ui--mix--home--spacecraft-item-component-name">
Bla Bla
</div>
</div>
</div>
<!--OR Hashed version-->
<div class="ui--mix--home--spacecraft-item-component" data-controller="ui--mix--home--spacecraft-item-component">
<div class="wrapper_jhb45" data-action="click->ui--mix--home--spacecraft-item-component#handleClick">
<div class="avatar_6fjGFD6">
</div>
<div class="name_kj5fHG0">
Bla Bla
</div>
</div>
</div> You can see we changed only classes which was inside As you can see it doesn't matter for this feature how user bundles styles, by each component or by one big entry bundle, that's not our trouble haha😅 |
@camertron Have you think about that? Otherwise it would be fine to have some transpile callback, so users can realize this or anything else by himself |
@camertron bump👆 |
Hmm I'm not sure I understand. Where does this config value get set? In application.rb maybe? class Application < Rails::Application
config.rux.vcss = true # is this correct?
end
I'm not sure, I don't have much experience with all the new asset options in Rails these days. We just need to make it easy to configure whatever tool to process CSS files. If you think that doesn't require any magic on rux's part, then cool 😎
Right yeah that's great 😄 Would rux look for an class Component < ViewComponent::Base
styles do
Styles.new(
wrapper: "wrapper",
avatar: "avatar",
name: "name"
)
end
end What do you think?
Ahh yes I like that! Make it easy to switch between them in case you want one style or the other 👍 |
Ohh @camertron i totally agree with you. I think this way is cool: styles do
Styles.new(
wrapper: "wrapper",
avatar: "avatar",
name: "name"
)
end And about configuration: i think it can be in Rails.application.configure do
config.rux.vcss = true
... Do you think that's possible?😄 I really need that and i'm sure that's a revolutionize feature |
Awesome!
Right ok that makes sense. I still think this functionality should eventually live in a separate gem, but we can always extract it later.
Yes, I definitely think it's possible! Are you volunteering to work on it? |
@camertron I don't think i have time for that, but if i can help somehow a little - let me know😄 |
Hey @camertron can i help somehow to make this feature?😅 |
Hey @serhiijun, sure, feel free to dive in and submit a PR 😄 Maybe a good place to start is adding the |
Same to css-in-js it would be fine to have bundled css from my rux component too.
Let's say, we have this folder structure:
And my_component.rux looks like this
And
my_component.rcss
like this:And while Rux transpiles .rux component - it also transpiles .rcss file from this component to .css file, which may looks like this after:
As you can see - now our css selectors is uniq.
Why we need that - well, this is super simple example, but let's imagine we have 50 components. Each of them may have .wrapper or .avatar or anything same classes. Now solving that will looks like nesting css selectors:
By this way our bundle will have ton of KB lol
Or another way same to:
This way so fast will make our code super ugly. So, my proposal is realise transpiling rcss to css which will have uniq version of selectors so our code will be clean and our bundle will be super light weight.
The text was updated successfully, but these errors were encountered: