Lynx

Vanilla Extract

Guides how to generate static CSS with Vanilla Extract in Lynx and use Crispy tokens.

Vanilla Extract extracts styles written in TypeScript to CSS at build time. Define styles in .css.ts and apply the generated class names to the className of Lynx native elements. You don't need to generate static styles in JavaScript every time they render.

Requirements and Installation

rspeedy-plugin-vanilla-extract adds Rspeedy-compatible processing to Vanilla Extract's webpack plugin. This guide is based on the dependency conditions of the released plugin 0.2.0.

PackageCondition
@rsbuild/core1.x
webpack5.x
Rspeedy and ReactLynx pluginsVersions compatible with the Rsbuild environment above

First check which Rsbuild version your project's Rspeedy uses. The peer dependency of plugin 0.2.0 is @rsbuild/core: ^1. Simply installing @rsbuild/core@1 on an Rsbuild 2-based project doesn't ensure compatibility. If you're using Rsbuild 2, check the plugin version that supports it or refer to the Tailwind CSS 4 guide.

Install common Crispy packages from Installation, then add the following dependencies.

npm install @vanilla-extract/css
npm install -D rspeedy-plugin-vanilla-extract@0.2.0 @rsbuild/core@1 webpack@5

Rspeedy Configuration

Add pluginVanillaExtract({}) to the plugin list in your existing lynx.config.ts. Keep existing ReactLynx plugin and Crispy feature flags configuration.

lynx.config.ts
import { defineConfig } from "@lynx-js/rspeedy";
import { pluginVanillaExtract } from "rspeedy-plugin-vanilla-extract";

export default defineConfig({
  // ... existing configuration
  plugins: [
    // ... existing plugins
    pluginVanillaExtract({}),
  ],
});

Import Crispy CSS

src/styles/global.css
@import "@seed-design/lynx-css/base.css";
src/index.tsx
import "./styles/global.css";

Importing the TypeScript reference for tokens alone does not declare the token values, so be sure to also load base.css. In Lynx, use @seed-design/lynx-css instead of the web @seed-design/css. For the color mode settings of the root <page>, refer to Theming.

Using Styles and Crispy Tokens

src/App.css.ts
import { vars } from "@seed-design/lynx-css/vars";
import { style } from "@vanilla-extract/css";

export const root = style({
  display: "flex",
  flexDirection: "column",
  rowGap: vars.$dimension.x2,
  padding: vars.$dimension.x4,
  backgroundColor: vars.$color.bg.layerDefault,
  borderRadius: vars.$radius.r3,
});

export const label = style({
  color: vars.$color.fg.neutral,
  fontSize: vars.$fontSize.t4,
  lineHeight: vars.$lineHeight.t4,
  fontWeight: vars.$fontWeight.medium,
});
src/App.tsx
import * as styles from "./App.css";

export function App() {
  return (
    <view className={styles.root}>
      <text className={styles.label}>First item</text>
      <text className={styles.label}>Second item</text>
    </view>
  );
}

Table of contents