Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 40 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions rsbuild/stylex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ During development, `runtimeInjection` injects StyleX styles at runtime so style

In production, runtime injection is disabled. The plugin compiles StyleX at build time and appends the generated CSS to the stylesheet emitted by Rsbuild's `CssExtractRspackPlugin` (fed by `src/index.css`), producing content-hashed CSS filenames instead of a separate hardcoded `/stylex.css` link.

This example uses `stylex.webpack()` (not `stylex.rspack()`) because `@stylexjs/unplugin` currently attaches CSS injection through the webpack-compatible hook; Rspack still runs that hook for plugins registered via `tools.rspack.plugins`.

## Setup

Install the dependencies:
Expand Down
2 changes: 1 addition & 1 deletion rsbuild/stylex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@rsbuild/core": "2.2.12",
"@rsbuild/plugin-react": "^2.1.1",
"@stylexjs/unplugin": "^0.19.1",
"@stylexjs/unplugin": "^0.19.2",
"@types/node": "^24.19.2",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
Expand Down
8 changes: 2 additions & 6 deletions rsbuild/stylex/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import stylex from '@stylexjs/unplugin';
import stylexPlugin from '@stylexjs/unplugin/rspack';

export default defineConfig({
plugins: [pluginReact()],
Expand All @@ -10,11 +10,7 @@ export default defineConfig({
// Official StyleX plugin: compiles StyleX and appends CSS into the
// stylesheet emitted by CssExtractRspackPlugin (used by Rsbuild).
// See https://stylexjs.com/docs/learn/installation/rspack/
//
// Prefer the webpack adapter here: @stylexjs/unplugin currently attaches
// CSS injection via the webpack() hook, which Rspack still invokes for
// webpack-compatible plugins. The rspack() entry only runs transform.
stylex.webpack({
stylexPlugin({
useCSSLayers: true,
// Inject styles during development so they update with HMR.
runtimeInjection: process.env.NODE_ENV === 'development',
Expand Down