diff --git a/rsbuild/stylex/README.md b/rsbuild/stylex/README.md index a4ccee83..4123fce0 100644 --- a/rsbuild/stylex/README.md +++ b/rsbuild/stylex/README.md @@ -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`. diff --git a/rsbuild/stylex/rsbuild.config.ts b/rsbuild/stylex/rsbuild.config.ts index a54d0883..1d2434af 100644 --- a/rsbuild/stylex/rsbuild.config.ts +++ b/rsbuild/stylex/rsbuild.config.ts @@ -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', }), ], },