Skip to content
Merged
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
4 changes: 3 additions & 1 deletion rsbuild/stylex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Minimal example of using [StyleX](https://stylexjs.com/) with Rsbuild via the official [`@stylexjs/unplugin`](https://stylexjs.com/docs/learn/installation/rspack/) adapter.

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`). StyleX styles therefore stay in the normal CSS asset pipeline with content-hashed filenames, instead of a separate hardcoded `/stylex.css` link.
During development, `runtimeInjection` injects StyleX styles at runtime so style changes apply through HMR without a page refresh.

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`.

Expand Down
2 changes: 2 additions & 0 deletions rsbuild/stylex/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default defineConfig({
// webpack-compatible plugins. The rspack() entry only runs transform.
stylex.webpack({
useCSSLayers: true,
// Inject styles during development so they update with HMR.
runtimeInjection: process.env.NODE_ENV === 'development',
}),
],
},
Expand Down
Loading