Skip to content

CSS Extraction at build-time #433

Open
@davesnx

Description

@davesnx

We can remove the runtime completely and go for static styles. Generate CSS files in the _build folder (for Melange/native) and in-source in ReScript.

  • We will remove the runtime completely allowing much faster implementation
  • Output real CSS (can be extracted to a new file, cached)
    • Need to know how to generate files on the same folder (both in rescript and melange)
  • Dynamic components can be translated to CSS variables
  • We can have development type-safety if we keep the parsing/type-checking + inline styles at run-time.
    • Not sure how thought, maybe with unboxed?
  • We already have a css-in-js logic implemented in native

Design

styled.div

module C = [%styled.div "height: 100%"]
(* pushes into the Stylesheet ".div12312 {height: 100%}" *)
(* module C = <div className="div12312" /> *)

module C = [%styled.div (~what) => "width: $(what); height: 100%"]
(* pushes static properties ".div12312 {height: 100%}" *)
(* generates dynamic properties with CSS vars ".div12345 {width: (--var-what)}" *)
(* module C = <div className="div12312 div12345" style={ReactDOM.Style.make("--var-what": what)} /> *)

cx

let cx = [%cx "height: 100%"]
(* pushes properties ".hash {height: 100%}" *)
(* let cx = ".hash" *)

Ideal plan

Similar implementations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions