Skip to content

refactor: migrate from webpack to rspack#17

Merged
chenjiahan merged 2 commits intomainfrom
to_rspack_0314
Mar 14, 2026
Merged

refactor: migrate from webpack to rspack#17
chenjiahan merged 2 commits intomainfrom
to_rspack_0314

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

  • update all imports, types, and configurations to use @rspack/core instead of webpack
  • remove webpack dependency and add @rspack/core as a peer dependency
  • update tests and documentation to reflect the change to rspack

Copilot AI review requested due to automatic review settings March 14, 2026 13:19
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring effort to transition the project's build system from Webpack to Rspack. The primary goal is to leverage Rspack's performance benefits and modern architecture, ensuring the project remains current with contemporary build tooling. This change impacts core configurations, type definitions, and testing infrastructure, providing a more optimized and potentially faster development experience.

Highlights

  • Core Dependency Migration: The project has been refactored to migrate its core bundling dependency from Webpack to Rspack, updating all relevant imports, types, and configurations.
  • Dependency Management Update: The package.json and pnpm-lock.yaml files were updated to remove Webpack as a dependency and introduce @rspack/core as a peer dependency, along with its associated native bindings.
  • Documentation and Test Alignment: Documentation examples in README.md and test configurations, including snapshot files and test helpers, were adjusted to reflect the switch to Rspack.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • README.md
    • Updated code examples to use rspack instead of webpack for compiler instantiation.
    • Modified import statements to destructure rspack from @rspack/core.
  • jest.config.js
    • Removed the snapshotResolver configuration entry.
  • package.json
    • Added @rspack/core as a development dependency.
    • Removed webpack from development dependencies.
    • Updated peerDependencies and peerDependenciesMeta to reference @rspack/core instead of webpack.
  • pnpm-lock.yaml
    • Added @rspack/core and its various platform-specific binding packages.
    • Removed webpack and its related entries.
  • scripts/globalSetup.js
    • Changed the import of version from webpack to @rspack/core.
    • Updated the console log message to indicate running tests for rspack.
  • src/index.js
    • Updated JSDoc typedefs to import Compiler, MultiCompiler, Configuration, Stats, and MultiStats from @rspack/core.
    • Added new JSDoc typedefs for DevServerOption and ClosableWatching.
    • Introduced a type assertion for filledContext.watching.close to ClosableWatching.
  • src/utils/getPaths.js
    • Updated JSDoc typedefs to import Compiler, Stats, MultiStats, and Asset from @rspack/core.
    • Added DevServerOption to JSDoc typedef imports.
    • Modified the return type of assetsInfo to Map<string, Asset["info"]> | undefined.
    • Added type assertions for options.publicPath and compilation.options.devServer.
  • src/utils/setupHooks.js
    • Updated JSDoc typedefs to import Configuration, Compiler, MultiCompiler, Stats, and MultiStats from @rspack/core.
    • Removed Webpack-specific logic for determining color support in stats options.
  • src/utils/setupOutputFileSystem.js
    • Updated JSDoc typedefs to import MultiCompiler from @rspack/core.
    • Added DevServerOption to JSDoc typedef imports and used it for type assertions.
  • src/utils/setupWriteToDisk.js
    • Updated JSDoc typedefs to import Compiler, MultiCompiler, and Compilation from @rspack/core.
    • Added DevServerOption to JSDoc typedef imports and used it for type assertions.
  • test/snapshots/logging.test.js
    • Added a new snapshot file containing Rspack-specific logging output.
  • test/snapshots/logging.test.js.snap.webpack5
    • Removed the old Webpack 5 snapshot file.
  • test/helpers/getCompiler.js
    • Changed the compiler import from webpack to rspack from @rspack/core.
  • test/helpers/runner.js
    • Changed the compiler import from webpack to rspack from @rspack/core.
  • test/helpers/snapshotResolver.js
    • Removed the custom snapshot resolver file.
  • test/middleware.test.js
    • Changed the Stats import from webpack to @rspack/core.
  • test/utils/snapshots/setupHooks.test.js
    • Renamed snapshot file from .snap.webpack5 to .snap.
  • test/utils/snapshots/setupWriteToDisk.test.js
    • Renamed snapshot file from .snap.webpack5 to .snap.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@chenjiahan chenjiahan merged commit dd85900 into main Mar 14, 2026
2 of 7 checks passed
@chenjiahan chenjiahan deleted the to_rspack_0314 branch March 14, 2026 13:19
Copy link
Copy Markdown

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

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 project from webpack to rspack, updating dependencies, configurations, types, and documentation accordingly. The changes are generally well-executed. However, I've identified a few areas for improvement. There are several outdated comments in the README that still refer to webpack. Additionally, there's a potentially risky use of an any type cast when handling publicPath which could lead to runtime errors. Finally, there's an inconsistency in how stats colors are handled for multi-compiler mode compared to single-compiler mode. I've provided specific comments and suggestions to address these points.

Comment on lines 39 to 45
const publicPath = options.publicPath
? compilation.getPath(options.publicPath)
? compilation.getPath(/** @type {any} */ (options.publicPath))
: compilation.outputOptions.publicPath
? compilation.getPath(compilation.outputOptions.publicPath)
? compilation.getPath(
/** @type {any} */ (compilation.outputOptions.publicPath),
)
: "";
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

Using an any cast for publicPath is risky because this option can be a function. Passing a function to compilation.getPath will likely cause a runtime error. Please consider adding a type check to handle the case where publicPath is a function, or add a comment explaining why this cast is safe if it is guaranteed to not be a function in practice.


const compiler = webpack({
const compiler = rspack({
// webpack options
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
// webpack options
// rspack options

const { rspack } = require("@rspack/core");

const configuration = {
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */


const compiler = webpack({
const compiler = rspack({
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */

const { rspack } = require("@rspack/core");

const configuration = {
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */


const compiler = webpack({
const compiler = rspack({
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */


const compiler = webpack({
const compiler = rspack({
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */


const compiler = webpack({
const compiler = rspack({
// webpack options
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
// webpack options
// rspack options


const compiler = webpack({
const compiler = rspack({
/* Webpack configuration */
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

For consistency with the migration to rspack, this comment should be updated to refer to rspack instead of webpack.

Suggested change
/* Webpack configuration */
/* rspack configuration */

Comment on lines 108 to 112
(childStatsOptions) => {
childStatsOptions = normalizeStatsOptions(childStatsOptions);

if (typeof childStatsOptions.colors === "undefined") {
const [firstCompiler] =
/** @type {MultiCompiler} */
(compiler).compilers;

// TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
childStatsOptions.colors =
typeof firstCompiler.webpack !== "undefined" &&
typeof firstCompiler.webpack.cli !== "undefined" &&
typeof firstCompiler.webpack.cli.isColorSupported ===
"function"
? firstCompiler.webpack.cli.isColorSupported()
: require("colorette").isColorSupported;
}

return childStatsOptions;
},
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

The logic for setting colors on stats options for multi-compiler mode has been removed. This is inconsistent with the single-compiler mode, which still has color detection logic. This could result in stats output without colors in multi-compiler mode. The color detection logic should be added back, simplified to use colorette like in the single-compiler case.

Suggested change
(childStatsOptions) => {
childStatsOptions = normalizeStatsOptions(childStatsOptions);
if (typeof childStatsOptions.colors === "undefined") {
const [firstCompiler] =
/** @type {MultiCompiler} */
(compiler).compilers;
// TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
childStatsOptions.colors =
typeof firstCompiler.webpack !== "undefined" &&
typeof firstCompiler.webpack.cli !== "undefined" &&
typeof firstCompiler.webpack.cli.isColorSupported ===
"function"
? firstCompiler.webpack.cli.isColorSupported()
: require("colorette").isColorSupported;
}
return childStatsOptions;
},
(childStatsOptions) => {
childStatsOptions = normalizeStatsOptions(childStatsOptions);
if (typeof childStatsOptions.colors === "undefined") {
childStatsOptions.colors = require("colorette").isColorSupported;
}
return childStatsOptions;
}

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates this dev-middleware package from the webpack toolchain/types to Rspack by updating runtime code paths, type declarations, tests/snapshots, and documentation accordingly.

Changes:

  • Replace webpack imports/types with @rspack/core across source and generated .d.ts files.
  • Update test helpers and Jest setup to use Rspack, including snapshot format/name changes.
  • Update package metadata (deps/peerDeps) and README examples for Rspack usage.

Reviewed changes

Copilot reviewed 16 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/index.js Switch core public types to @rspack/core and adjust watching close typing.
src/utils/setupHooks.js Update stats typing/imports for Rspack and simplify color support detection.
src/utils/setupOutputFileSystem.js Update compiler typing and devServer option checks for Rspack configs.
src/utils/setupWriteToDisk.js Update compiler/compilation typing and devServer option checks.
src/utils/getPaths.js Update stats/asset typing for Rspack and change how assetsInfo is derived.
types/index.d.ts Update exported public types to @rspack/core and add DevServerOption/ClosableWatching.
types/utils/setupHooks.d.ts Switch configuration/compiler/stats types to @rspack/core.
types/utils/setupOutputFileSystem.d.ts Switch multi-compiler type to @rspack/core and re-export DevServerOption.
types/utils/setupWriteToDisk.d.ts Switch compiler types to @rspack/core and re-export DevServerOption.
types/utils/getPaths.d.ts Switch stats/asset types to @rspack/core and update assetsInfo typing.
test/helpers/runner.js Use rspack() instead of webpack() to build compilers for integration tests.
test/helpers/getCompiler.js Use rspack() instead of webpack() for compiler helper.
test/middleware.test.js Update test-side Stats import to come from @rspack/core.
scripts/globalSetup.js Print Rspack version in test setup instead of webpack version.
jest.config.js Remove custom snapshot resolver in favor of Jest defaults.
test/helpers/snapshotResolver.js Remove webpack-versioned snapshot resolver implementation.
test/__snapshots__/logging.test.js Add new snapshot outputs matching Rspack logging format.
test/__snapshots__/logging.test.js.snap.webpack5 Remove old webpack5 snapshot set.
test/utils/__snapshots__/setupHooks.test.js.snap Add/refresh snapshots for updated hook behavior.
test/utils/__snapshots__/setupWriteToDisk.test.js.snap Add/refresh snapshots for updated write-to-disk behavior.
test/utils/__snapshots__/setupHooks.test.js (New) snapshot module file added alongside .snap.
test/utils/__snapshots__/setupWriteToDisk.test.js (New) snapshot module file added alongside .snap.
package.json Remove webpack, add @rspack/core (dev + peer), update package metadata accordingly.
pnpm-lock.yaml Reflect dependency graph changes for @rspack/core and related bindings.
README.md Update usage examples from webpack to rspack.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,387 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

Comment on lines +40 to +48
? compilation.getPath(/** @type {any} */ (options.publicPath))
: compilation.outputOptions.publicPath
? compilation.getPath(compilation.outputOptions.publicPath)
? compilation.getPath(
/** @type {any} */ (compilation.outputOptions.publicPath),
)
: "";
const assetsInfo = new Map(
compilation.getAssets().map((asset) => [asset.name, asset.info]),
);
Comment on lines 12 to 14
* @param {import("../index.js").FilledContext<Request, Response>} context context
* @returns {{ outputPath: string, publicPath: string, assetsInfo: Asset["info"] }[]} paths
* @returns {{ outputPath: string, publicPath: string, assetsInfo: Map<string, Asset["info"]> | undefined }[]} paths
*/
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 127c767fe0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1,387 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Rename logging snapshot file to .snap

After removing the custom snapshotResolver, Jest falls back to its default snapshot naming (*.snap), but this commit adds test/__snapshots__/logging.test.js instead; that filename matches testMatch (**/test/**/*.test.js), so Jest treats it as a test file (with no tests) and fails test runs, while snapshot assertions in logging.test.js no longer read this artifact. Renaming it to logging.test.js.snap fixes both problems.

Useful? React with 👍 / 👎.

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.

2 participants