Skip to content

[WIP] Migrate webpack to rspack - node16#183

Open
liaoyu wants to merge 3 commits into
qiniu:masterfrom
liaoyu:feat/rspack-node16
Open

[WIP] Migrate webpack to rspack - node16#183
liaoyu wants to merge 3 commits into
qiniu:masterfrom
liaoyu:feat/rspack-node16

Conversation

@liaoyu

@liaoyu liaoyu commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator
  • node16 required

liaoyu added 2 commits May 29, 2026 15:40
迁移 generate/serve 与 webpack 配置到 rspack,新增 ESM 动态加载适配层,并更新相关依赖与 Node 版本要求。
移除 ESM 动态加载与 Rspack 2 专用适配,改用直接 import 和 Rspack 1.x API。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/serve.ts
Comment on lines +95 to 103
await new Promise<void>((resolve, reject) => {
server.startCallback((err: Error | undefined) => {
if (err) {
reject(err)
return
}
resolve()
})
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

In @rspack/dev-server v1.x (which is aligned with webpack-dev-server v5), the legacy startCallback method has been removed. You should use the promise-based start() method instead.

  await server.start()

Comment thread src/serve.ts
Comment on lines 118 to 122
return () => new Promise<void>(resolve => {
server.close(resolve)
server.stopCallback(() => {
resolve()
})
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

In @rspack/dev-server v1.x (aligned with webpack-dev-server v5), the legacy stopCallback method has been removed. You should use the promise-based stop() method instead.

  return () => server.stop()

Comment thread src/serve.ts
Comment on lines +127 to +132
interface ProxyEntryOptions {
changeOrigin: boolean
logLevel: 'silent'
onProxyReq(proxyReq: ClientRequest): void
onProxyRes(proxyRes: IncomingMessage): void
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  }
}

Comment thread src/webpack/transform.ts
Comment on lines +154 to +155
// Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64
localIdentHashDigest: 'xxhash64'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
// Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64
localIdentHashDigest: 'xxhash64'
// Node 17+ / OpenSSL 3 不再支持 MD4,需使用 xxhash64
localIdentHashFunction: 'xxhash64'

Comment thread src/webpack/index.ts
Comment on lines +142 to +146
new ImageMinimizerPlugin({
use: 'jpeg',
test: /\.(?:jpg|jpeg|jpe)$/i,
quality: 65
}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
        }
      }),

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary:

  • Code quality: one SWC React runtime compatibility regression.
  • Performance: No issues found.
  • Security: No issues found.
  • Documentation/config accuracy: one Node support mismatch.

Comment thread src/webpack/swc.ts
useDefineForClassFields: true,
...(withReact && {
react: {
runtime: 'automatic',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread package.json
},
"engines": {
"node": ">=12"
"node": ">=16.0.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant