Skip to content

Commit 6a4e05c

Browse files
JSerFengchenjiahan
andauthored
docs: add HMR workaround for vanilla-extract-css plugin (#6053)
Co-authored-by: neverland <[email protected]>
1 parent 61fb775 commit 6a4e05c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

website/docs/en/guide/styling/css-in-js.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Please note, you must select the SWC plugin that matches the current version of
6767

6868
Rsbuild supports [@vanilla-extract/webpack-plugin](https://npmjs.com/package/@vanilla-extract/webpack-plugin). You can add the following config to use [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract):
6969

70+
Currently, Rspack has an [HMR issue](https://github.com/web-infra-dev/rsbuild/issues/6049) when using `splitChunks` together with `@vanilla-extract/webpack-plugin`. In development mode, you can use a special `splitChunks` configuration to work around this issue.
71+
7072
```ts title="rsbuild.config.ts"
7173
import { defineConfig } from '@rsbuild/core';
7274
import { pluginReact } from '@rsbuild/plugin-react';
@@ -80,6 +82,20 @@ export default defineConfig({
8082
},
8183
}),
8284
],
85+
performance: {
86+
chunkSplit: {
87+
override: {
88+
cacheGroups: {
89+
vanilla: {
90+
test: /@vanilla-extract\/webpack-plugin/,
91+
// make sure the chunk contains modules created by @vanilla-extract/webpack-plugin has stable id in development mode to avoid HMR issues
92+
name: process.env.NODE_ENV === 'development' && 'vanilla',
93+
chunks: 'all',
94+
},
95+
},
96+
},
97+
},
98+
},
8399
tools: {
84100
rspack: {
85101
plugins: [new VanillaExtractPlugin()],

website/docs/zh/guide/styling/css-in-js.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export default defineConfig({
6767

6868
Rsbuild 支持使用 [@vanilla-extract/webpack-plugin](https://npmjs.com/package/@vanilla-extract/webpack-plugin) 插件,你可以添加以下配置来使用 [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract)
6969

70+
目前,Rspack 在同时使用 `splitChunks``@vanilla-extract/webpack-plugin` 时存在一个 [HMR 问题](https://github.com/web-infra-dev/rsbuild/issues/6049)。在开发模式下,你可以使用特殊的 `splitChunks` 配置来规避这个问题。
71+
7072
```ts title="rsbuild.config.ts"
7173
import { defineConfig } from '@rsbuild/core';
7274
import { pluginReact } from '@rsbuild/plugin-react';
@@ -80,6 +82,20 @@ export default defineConfig({
8082
},
8183
}),
8284
],
85+
performance: {
86+
chunkSplit: {
87+
override: {
88+
cacheGroups: {
89+
vanilla: {
90+
test: /@vanilla-extract\/webpack-plugin/,
91+
// 确保在开发模式下 @vanilla-extract/webpack-plugin 产生虚拟模块所在的 Chunk id 稳定以避免 HMR 问题
92+
name: process.env.NODE_ENV === 'development' && 'vanilla',
93+
chunks: 'all',
94+
},
95+
},
96+
},
97+
},
98+
},
8399
tools: {
84100
rspack: {
85101
plugins: [new VanillaExtractPlugin()],

0 commit comments

Comments
 (0)