Skip to content

Commit f12e47f

Browse files
authored
fix: prefer using Rspack/Rsbuild v2 config (#470)
* chore(deps): upgrade Rsbuild/Rspack to 2.0.0-rc.2 - Bump `@rsbuild/core` devDependencies to `^2.0.0-rc.2` across all packages - Bump sandbox plugins to Rsbuild v2 compatible versions: - `@rsbuild/plugin-react` → `^2.0.0-rc.2` - `@rsbuild/plugin-vue` → `^2.0.0-alpha.3` - `@rsbuild/plugin-sass` → `^2.0.0-alpha.3` - `@rsbuild/plugin-babel` → `^2.0.0-alpha.3` - `@rspack/core` / `@rspack/cli` → `^2.0.0-rc.2` - `@rspack/plugin-react-refresh` → `^2.0.0` - Migrate `performance.chunkSplit` to top-level `splitChunks` for Rsbuild v2, with runtime version detection to preserve Rsbuild v1 compatibility - Add `// Rspack v1 compatible:` comments to all v1 compat code paths - All peerDependencies remain `^1.5.0 || ^2.0.0-0` (no major version bump) * fix(addon-modernjs): cast RsbuildConfig to align cross-package types Modern.js internally resolves a different version of @rsbuild/core, causing RsbuildConfig type mismatch with mergeRsbuildConfig. * fix: revert incompatible sandbox plugin versions - Keep `performance.chunkSplit` for both v1 and v2 since `@rsbuild/plugin-vue@2.0.0-alpha.3` still reads `chunkSplit.strategy` - Revert `@rsbuild/plugin-sass` to `^1.5.1` in rslib sandboxes (v2 alpha has breaking changes with sass module resolution) - Revert `@rspack/plugin-react-refresh` to `^1.6.1` (v2 is ESM-only, incompatible with CJS rspack config) * fix(sandboxes): migrate rspack config to ESM and fix plugin compat - Convert `rspack.config.cjs` to `rspack.config.mjs` for `@rspack/plugin-react-refresh@2.0.0` ESM compatibility - Use named export `ReactRefreshRspackPlugin` (v2 dropped default export) - Keep `@rsbuild/plugin-sass@^1.5.1` in rslib sandboxes since `@rsbuild/plugin-sass@2.0.0-alpha.3` is too old for `@rsbuild/core@rc.2` * fix(builder-rsbuild): use rspackVersion for version detection, drop splitChunks - Use `rspack.rspackVersion` instead of `rspack.version` for major version detection. `rspack.version` returns the webpack-compat version (5.75.0), not the actual Rspack version. - Remove top-level `splitChunks` config to avoid overriding user-provided `performance.chunkSplit` settings from rsbuild.config. When both are present, Rsbuild v2 ignores `performance.chunkSplit` entirely. - Keep using `performance.chunkSplit` only, which is deprecated but still functional in Rsbuild v2, preserving v1 compatibility. * fix(builder-rsbuild): use v1/v2 conditional splitChunks and revert plugin-vue - Use rspackMajorVersion to conditionally apply `performance.chunkSplit` (v1) or top-level `splitChunks` (v2) instead of deprecated-but-functional fallback. - Revert `@rsbuild/plugin-vue` to 1.2.7 in vue3/lit/rslib-vue3 sandboxes because alpha.3 crashes when `performance.chunkSplit` is absent in v2 branch.
1 parent 5769aa3 commit f12e47f

File tree

28 files changed

+669
-993
lines changed

28 files changed

+669
-993
lines changed

packages/addon-modernjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"devDependencies": {
4949
"@modern-js/app-tools": "^3.1.2",
5050
"@modern-js/plugin": "^3.1.2",
51-
"@rsbuild/core": "^2.0.0-rc.0",
51+
"@rsbuild/core": "^2.0.0-rc.2",
5252
"@types/node": "^22.0.0",
5353
"storybook": "10.3.5",
5454
"storybook-builder-rsbuild": "workspace:*",

packages/addon-modernjs/src/preset.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
parseRspackConfig as parseToRsbuildConfig,
66
} from '@modern-js/app-tools/builder'
77
// TODO: better import from `@modern-js/app-tools/builder`
8-
import { mergeRsbuildConfig } from '@rsbuild/core'
8+
import { mergeRsbuildConfig, type RsbuildConfig } from '@rsbuild/core'
99
import findUp from 'find-up'
1010
import { logger } from 'rslog'
1111
import type {
@@ -124,6 +124,7 @@ export const rsbuildFinal: StorybookConfigRsbuild['rsbuildFinal'] = async (
124124
builderPluginAdapterHooks(adapterParams),
125125
]
126126

127-
const finalConfig = mergeRsbuildConfig(config, rsbuildConfig)
127+
// Modern.js may resolve a different version of @rsbuild/core, cast to align types.
128+
const finalConfig = mergeRsbuildConfig(config, rsbuildConfig as RsbuildConfig)
128129
return finalConfig
129130
}

packages/addon-rslib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"prepare": "pnpm run build"
4343
},
4444
"devDependencies": {
45-
"@rsbuild/core": "^2.0.0-rc.0",
45+
"@rsbuild/core": "^2.0.0-rc.2",
4646
"@rslib/core": "^0.20.3",
4747
"@types/node": "^22.0.0",
4848
"storybook": "10.3.5",

packages/builder-rsbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"util-deprecate": "^1.0.2"
7070
},
7171
"devDependencies": {
72-
"@rsbuild/core": "^2.0.0-rc.0",
72+
"@rsbuild/core": "^2.0.0-rc.2",
7373
"@storybook/core-webpack": "10.3.5",
7474
"@types/fs-extra": "^11.0.4",
7575
"@types/node": "^22.0.0",

packages/builder-rsbuild/src/plugins/rspack-inject-mocker-runtime-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class RspackInjectMockerRuntimePlugin {
88
compiler: Rspack.Compiler,
99
): typeof HtmlRspackPlugin | null {
1010
try {
11+
// Rspack v1 compatible: check for both `HtmlRspackPlugin` (v2) and `HtmlWebpackPlugin` (v1) names.
1112
const pluginConstructor = compiler.options.plugins?.find((plugin) => {
1213
const name = plugin?.constructor?.name
1314
return name === 'HtmlRspackPlugin' || name === 'HtmlWebpackPlugin'

packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module'
22
import { dirname, join, resolve } from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import type { RsbuildConfig, Rspack } from '@rsbuild/core'
5-
import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core'
5+
import { loadConfig, mergeRsbuildConfig, rspack } from '@rsbuild/core'
66
import { pluginTypeCheck } from '@rsbuild/plugin-type-check'
77
// @ts-expect-error (I removed this on purpose, because it's incorrect)
88
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'
@@ -61,6 +61,8 @@ const getRspackMajorVersion = (version: unknown): number | null => {
6161
return Number.isNaN(major) ? null : major
6262
}
6363

64+
const rspackMajorVersion = getRspackMajorVersion(rspack.rspackVersion)
65+
6466
/** @see https://github.com/web-infra-dev/rsbuild/blob/d8204bb72b5dd32dc736372dff6bb618675a4ad5/packages/core/src/constants.ts#L61 */
6567
const RAW_QUERY_REGEX = /[?&]raw(?:&|=|$)/
6668

@@ -281,15 +283,28 @@ export default async (
281283
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
282284
},
283285
},
284-
performance: {
285-
chunkSplit: {
286-
strategy: 'custom',
287-
splitChunks: {
288-
chunks: 'all',
289-
},
290-
},
291-
buildCache: cacheConfig,
292-
},
286+
// Rsbuild v1 compatible: `performance.chunkSplit` is deprecated in Rsbuild v2, use top-level `splitChunks` instead.
287+
...(rspackMajorVersion === 1
288+
? {
289+
performance: {
290+
chunkSplit: {
291+
strategy: 'custom' as const,
292+
splitChunks: {
293+
chunks: 'all' as const,
294+
},
295+
},
296+
buildCache: cacheConfig,
297+
},
298+
}
299+
: {
300+
splitChunks: {
301+
preset: 'none' as const,
302+
chunks: 'all' as const,
303+
},
304+
performance: {
305+
buildCache: cacheConfig,
306+
},
307+
}),
293308
plugins: [
294309
shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null,
295310
pluginHtmlMinifierTerser(() => ({
@@ -394,7 +409,7 @@ export default async (
394409
].filter(Boolean),
395410
)
396411

397-
const rspackMajorVersion = getRspackMajorVersion(rspack.version)
412+
// Rspack v1 compatible: disable `outputModule` experiment which is not supported in Rspack v1.
398413
if (rspackMajorVersion === 1) {
399414
const experiments = (config.experiments ??= {}) as Record<
400415
string,

packages/framework-html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"tsconfig-paths": "^4.2.0"
5656
},
5757
"devDependencies": {
58-
"@rsbuild/core": "^2.0.0-rc.0",
58+
"@rsbuild/core": "^2.0.0-rc.2",
5959
"@types/node": "^22.0.0",
6060
"@types/resolve": "^1.20.6",
6161
"storybook": "10.3.5",

packages/framework-react-native-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"storybook-react-rsbuild": "workspace:*"
5454
},
5555
"devDependencies": {
56-
"@rsbuild/core": "^2.0.0-rc.0",
56+
"@rsbuild/core": "^2.0.0-rc.2",
5757
"@types/node": "^22.0.0",
5858
"@types/react": "^18.3.28",
5959
"react": "18.3.1",

packages/framework-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"tsconfig-paths": "^4.2.0"
6565
},
6666
"devDependencies": {
67-
"@rsbuild/core": "^2.0.0-rc.0",
67+
"@rsbuild/core": "^2.0.0-rc.2",
6868
"@types/node": "^22.0.0",
6969
"@types/react": "^18.3.28",
7070
"@types/resolve": "^1.20.6",

packages/framework-vue3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"vue-docgen-loader": "^2.0.1"
5252
},
5353
"devDependencies": {
54-
"@rsbuild/core": "^2.0.0-rc.0",
54+
"@rsbuild/core": "^2.0.0-rc.2",
5555
"@types/node": "^22.0.0",
5656
"storybook": "10.3.5",
5757
"typescript": "^5.9.3",

0 commit comments

Comments
 (0)