Giter VIP home page Giter VIP logo

Comments (6)

PepijnSenders avatar PepijnSenders commented on May 10, 2024 1

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.

cristianbote avatar cristianbote commented on May 10, 2024

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).

  1. 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
  2. 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:

Is this answering your question?
_

  1. It's more a serialization really, than a compilation, but oh well.

from goober.

cristianbote avatar cristianbote commented on May 10, 2024

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.

PepijnSenders avatar PepijnSenders commented on May 10, 2024

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.

PepijnSenders avatar PepijnSenders commented on May 10, 2024

And oh yeah that repo is a bit dead πŸ˜…, really need to start accepting some PR's again.

from goober.

cristianbote avatar cristianbote commented on May 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.