Closed kentcdodds closed 7 years ago
I added this on a branch for the SC babel plugin, but it'd work a lot better if it's wrapped in a webpack plugin. I suggest you aim to work on a webpack plugin that uses babel right from the start :)
I have early ideas working decently in glam It has constraints/caveats.
for glamorous, it'll looks something like this -
const MyDiv = glamorous.div`
padding: 20;
fontSize: ${({big}) => big ? 30 : 20 }
`
I'm still trying to work out ssr etc for glam.
That code snippit looks a lot like styled-components 😉 Seems like this work is more in line with that API :+1:
I really miss this feature from css-loader! Any way we can help/contribute? Thanks for filing this issue.
Awesome @ConAntonakos, could you work on this? https://github.com/kentcdodds/css-in-js-precompiler/issues/3
Indeed! I'm definitely still a novice when it comes to webpack plugins, but I'm glad it's at least getting attention. Thanks for opening these, @kentcdodds.
Most of us are novices. I've never really made a babel plugin either 🙃
@kentcdodds I'm actually about to start working on a generic CSS preprocessing and static CSS extraction library that will become the core of the new styled-components v3 features. I'll meet up with @threepointone to get started on it and lay out an API.
My goal is for it to not only work for styled-components, but for Glamorous and Glam as well, if that's not too ambitious. This way we could all rely on a stable preprocessing core library.
Since nothing's done yet, except for some initial code on the SC babel plugin of course, all I can show you is the logo that I've come up with ^^
That's freaky and awesome at the same time lol.
Hopefully my work so far is helpful!
Thanks for the update, @philpl! Looking forward to it and to contributing!
I'm going to go ahead and close this as it's a separate effort. Thanks!
Bringing this comment into its own issue:
I think that we could maybe write a babel plugin to take this:
to this:
Where the static styles are pre-processed and the resulting styles are extracted to a separate stylesheet, and we work with glamor's rehydration API to hook things up again. We'd need to update the
glamorousComponentFactory
API to accept a string class name, but that should be trivial. In any case, this would probably speed things up significantly.I just realized that based on the way we merge glamor class names with the styles they represent into a single class name may cause issues with this, but let's start with components that have static styles only, then maybe we can get it working with a combination of static and dynamic styles.
Anyone wanna write a plugin for this? If you've not made a Babel plugin before or worked with ASTs before, you can learn about it from my talk :)