Comments (6)
And I actually stumbled on this repo because I was also starting a super tiny preact project and was trying to add as little bytes as possible. Was going to add emotion initially but this looks like a much better fit!
from goober.
Hey @PepijnSenders!
Thanks for asking that! πI'm bound to do some write-up, that's for sure. I should add an issue to track that.
So, my main motivation was the size of the current solutions - well established and popular ones. I started a project, with Preact, and I was about to add 11k to the bundle, just for generating the styles. To put things in perspective, Preact has 3.5k, so over 3x the size of my view library?! I was having none of that. So, I started experimenting on how I could have a solution, with a familiar API, ala emotion, and have it under 1KB. Initially I managed to get it under 900B, but soon I realized my CSS parser was not gonna be maintainable. So, unfortunately I had to change the taglines πto reflect the reality I was facing - to have it under 1KB.
Generating the css, there's a 2-step process(since v1.0.2 π before it was 3).
- Parse the css string(from the tagged template) and create a AST-ish(an object basically) with the properties and blocks. https://github.com/cristianbote/goober/blob/master/src/core/parser/astish.js#L9
- Compile[1] that object into CSS(string with each block(object) with the proper selector parsed). https://github.com/cristianbote/goober/blob/master/src/core/parser/parse.js#L9
Once I figured how to handle these really generically, so there won't be a need to go and handle each block separately, it was just a matter of matching the features of the current solutions.
Also, at the moment we sit on the shoulders of such great css-in-js tools, so lots of learnings from there as well. For example:
- https://medium.com/styled-components/v3-1-0-such-perf-wow-many-streams-c45c434dbd03
- https://github.com/cxs-css/cxs, which has a zis of 0.7KB, but doesn't support tagged templates and styled API paradigm.
Is this answering your question?
_
- It's more a serialization really, than a compilation, but oh well.
from goober.
I just realized that you've already dabbled with these solutions π https://github.com/hellofresh/css-in-js-perf-tests. Just last night I wanted to add goober to the list and do the bench.
Also, @michael-klein, is about to add support for web-components and a more straight-forward css API πwhich I'm really excited about!
from goober.
Hey @cristianbote, wow that AST-ish stuff is some magic! Really cool. I actually worked with CXS before as well and found it to be a bit buggy at the time and the support for it kinda died. I really loved the functional syntax at the time though!
So if I understand you correctly libraries like styled-components and emotion parse a lot of stuff manually where you serialize it directly into usable CSS?
from goober.
And oh yeah that repo is a bit dead π , really need to start accepting some PR's again.
from goober.
Glad you considering it! π There's a much tiny solution, if you use webpack or rollup, at zero B runtime size, it's https://github.com/callstack/linaria. It's extracting the css into static files and there's the leverage.
from goober.
Related Issues (20)
- extractCss() returns empty string in Solid SSR environment HOT 2
- The behavior of `glob()` was changed in 2.1.11.
- Support for concurrent rendering + server components HOT 8
- Replace babel with swc HOT 1
- How to put styles inside web component? HOT 1
- Have component names inside classnames when in dev mode HOT 2
- Help solve typescript error trying to add new prop and doing conditional style HOT 2
- Use Proxy() for styled.div HOT 2
- How does goober compare to linaria? HOT 3
- Emotion is framework-agnostic
- Ability to set GOOBER_ID HOT 5
- [ Goober + Preact ] Error rendering during testing. HOT 2
- CSS string values do not work with extracted CSS HOT 4
- `css()` taken by surprise when `this` is `window` (in βold-schoolβ JS environment) HOT 1
- Duplicated styles within dynamic classes
- Unexpected behaviour when extending components HOT 1
- Running prefixer for nested objects
- Usage with rollup HOT 1
- Shave challenge clarification: which file should we be looking at? HOT 2
- deno server-side-render error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goober.