Skip to content

Can Theme-UI be statically extracted somehow? #1051

Answered by hasparus
hugomn asked this question in General
Discussion options

You must be logged in to vote

Hi! Theme UI is built on top of Emotion, and AFAIK it can't be statically extracted.

  • JSX pragma transforms sx props into className at runtime.
  • Similarly, themes are passed through React context.

@compiled/css-in-js has statically extracted CSS prop. If you knew the theme statically, it would possible to write a TS transform / babel plugin to compile sx prop into css prop and then run @compiled/css-in-js, but this is honestly a big undertaking.

It would look kind of like this: https://github.com/atlassian-labs/compiled-css-in-js/blob/master/packages/ts-transform/src/utils/object-literal-to-css.tsx

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@hugomn
Comment options

Answer selected by hugomn
Comment options

You must be logged in to vote
1 reply
@hasparus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants