Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 3.62 KB

README.md

File metadata and controls

42 lines (30 loc) · 3.62 KB

vanilla-extract example

Integrate Remix with vanilla-extract.

Preview

Open this example on CodeSandbox:

Open in CodeSandbox

Example

This example shows how to use vanilla-extract in Remix. Vanilla-extract is a zero-runtime CSS-in-TypeScript library that converts .css.ts files into static CSS at build time, providing first-class support for local-scoping of classes, variables, themes and more.

Architecture and Tradeoffs

  • A separate tsup process is needed to generate CSS, JavaScript and type definitions, whereas vanilla-extract is typically hooked up to your bundler. Effectively we're treating vanilla-extract more like a traditional CSS preprocessor like Sass or Less.
  • All styles from .css.ts files need to be manually re-exported from /.styles/index.ts which is then compiled into /app/styles for the Remix app to consume. You can think of it as maintaining a style manifest file. Conceptually this is the same as writing an index.scss file in Sass, except that JavaScript code and type definitions are generated in addition to CSS.
  • All styles are built into /app/styles/index.css which your Remix app needs to include via a links function.
  • Remix app code always needs to import styles from ~/styles, even if a .css.ts file is in the same directory as the Remix code that imports it. If you don't do this, your vanilla-extract styles won't be compiled properly as they will go directly through the Remix compiler.
  • You can keep the file size down using Sprinkles which generates compression-friendly atomic CSS. You can then access these classes at runtime via the type-safe sprinkles function.
  • To reduce boilerplate in your React code, Sprinkles can be wired up to a Box component as demonstrated in this project, allowing you to access atomic styles via props.

Relevant Files

Related Links