[WIP] Migrate webpack to rspack - node16#183
Conversation
liaoyu
commented
Jun 1, 2026
- node16 required
迁移 generate/serve 与 webpack 配置到 rspack,新增 ESM 动态加载适配层,并更新相关依赖与 Node 版本要求。
移除 ESM 动态加载与 Rspack 2 专用适配,改用直接 import 和 Rspack 1.x API。
There was a problem hiding this comment.
Code Review
This pull request migrates the build system from Webpack to Rspack, updating dependencies, configuration files, and loaders to support @rspack/core and @rspack/dev-server. The review feedback highlights several compatibility issues introduced by the migration: the legacy startCallback and stopCallback methods in @rspack/dev-server v1.x should be replaced with promise-based start() and stop() calls; proxy event handlers in http-proxy-middleware v3 must be nested under the on option; the css-loader v6 configuration needs to use localIdentHashFunction instead of localIdentHashDigest to avoid crashes on Node 17+; and the JPEG compression options in ImageMinimizerPlugin must be nested under the options property to be correctly applied.
| await new Promise<void>((resolve, reject) => { | ||
| server.startCallback((err: Error | undefined) => { | ||
| if (err) { | ||
| reject(err) | ||
| return | ||
| } | ||
| resolve() | ||
| }) | ||
| }) |
| return () => new Promise<void>(resolve => { | ||
| server.close(resolve) | ||
| server.stopCallback(() => { | ||
| resolve() | ||
| }) | ||
| }) |
| interface ProxyEntryOptions { | ||
| changeOrigin: boolean | ||
| logLevel: 'silent' | ||
| onProxyReq(proxyReq: ClientRequest): void | ||
| onProxyRes(proxyRes: IncomingMessage): void | ||
| } |
There was a problem hiding this comment.
In http-proxy-middleware v3 (used by @rspack/dev-server v1.x / webpack-dev-server v5), legacy event handlers like onProxyReq and onProxyRes have been removed. They must now be defined nested under the on option (e.g., on: { proxyReq, proxyRes }). Please update both this interface and the defaultProxyConfig object accordingly.
interface ProxyEntryOptions {
changeOrigin: boolean
logLevel: 'silent'
on: {
proxyReq(proxyReq: ClientRequest): void
proxyRes(proxyRes: IncomingMessage): void
}
}| // Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64 | ||
| localIdentHashDigest: 'xxhash64' |
There was a problem hiding this comment.
In css-loader v6, the option to configure the hash algorithm is localIdentHashFunction, not localIdentHashDigest. Using localIdentHashDigest will fail to set the hash function to xxhash64, causing it to default to md4 which crashes on Node 17+ / OpenSSL 3 environments.
| // Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64 | |
| localIdentHashDigest: 'xxhash64' | |
| // Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64 | |
| localIdentHashFunction: 'xxhash64' |
| new ImageMinimizerPlugin({ | ||
| use: 'jpeg', | ||
| test: /\.(?:jpg|jpeg|jpe)$/i, | ||
| quality: 65 | ||
| }), |
There was a problem hiding this comment.
In @rsbuild/plugin-image-compress's ImageMinimizerPlugin, compressor-specific options (such as quality for the jpeg compressor) must be nested under the options property instead of being defined at the top level. Otherwise, they will be ignored.
new ImageMinimizerPlugin({
use: 'jpeg',
test: /\\.(?:jpg|jpeg|jpe)$/i,
options: {
quality: 65
}
}),| useDefineForClassFields: true, | ||
| ...(withReact && { | ||
| react: { | ||
| runtime: 'automatic', |
There was a problem hiding this comment.
This changes SWC React builds to the automatic JSX runtime, while the Babel path still uses the classic runtime by default. Projects pinned to React versions without react/jsx-runtime (or projects relying on a custom pragma from tsconfig) will now emit imports that fail to resolve when optimization.swc is enabled. Consider keeping runtime: 'classic' unless the project opts in, or derive this from the project JSX settings.
| }, | ||
| "engines": { | ||
| "node": ">=12" | ||
| "node": ">=16.0.0" |
There was a problem hiding this comment.
Raising the package engine to Node 16 leaves the repo’s runtime/configuration signals inconsistent: .circleci/config.yml still tests Node 12/14 and Dockerfile still builds from Node 12. Please update those alongside this change (or document the remaining legacy targets) so CI and operator-facing images don’t keep advertising unsupported runtimes.