Skip to content

feat(@rspack-cli): make @rspack/dev-server and webpack-bundle-analyzer peer dependencies#12682

Closed
Kocal wants to merge 1 commit intoweb-infra-dev:mainfrom
Kocal:rspack-cli-peer-dependencies
Closed

feat(@rspack-cli): make @rspack/dev-server and webpack-bundle-analyzer peer dependencies#12682
Kocal wants to merge 1 commit intoweb-infra-dev:mainfrom
Kocal:rspack-cli-peer-dependencies

Conversation

@Kocal
Copy link

@Kocal Kocal commented Jan 8, 2026

Summary

Hi! 👋
This is my first PR here, do not hesitate to tell me if I didn't something wrong, thanks!

We are considering possibly replacing webpack by rspack in Webpack Encore
(a wrapper for webpack to make it easier to use in Symfony projects, existing for ~10 years now).

In Webpack Encore, we recently made webpack-dev-server an optional dependency (symfony/webpack-encore#1336), getting inspiration from e18e initiative. It allowed us to remove a tons of sub-dependencies and reduce the package size when not using some features.

But, when looking at @rspack/cli's npmgraph, I see it force to install ~225 dependencies (that's a lot!):

  • @rspack/dev-server is only useful when running rspack serve, and not all projects need it. Based on @rspack/dev-server's npmgraph, it brings ~207 dependencies,
  • webpack-bundle-analyzer is only useful when running rspack analyze, and not all projects need it. Based on webpack-bundle-analyzer's npmgraph, it brings ~16 dependencies

By making these two dependencies optional, we could reduce the number of dependencies to 2 (@discoveryjs/json-ext and webpack-bundle-analyzer).

It may be considered a breaking change, but it will only impact local development (not production builds), and only for people using rspack serve or rspack analyze.

WDYT? Thanks!

Related links

Checklist

  • [ ] Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 8, 2026 13:44
@Kocal Kocal requested a review from hardfist as a code owner January 8, 2026 13:44
@netlify
Copy link

netlify bot commented Jan 8, 2026

Deploy Preview for rspack ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7e42d29
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/695fb4cea394c300080b6ba0
😎 Deploy Preview https://deploy-preview-12682--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jan 8, 2026
Comment on lines +61 to +63
"@rspack/core": {
"optional": false
},
Copy link
Author

Choose a reason for hiding this comment

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

@rspack/core was already a peerDependency but it was not explicitly configured as non-optional.

Copy link
Contributor

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

This PR converts @rspack/dev-server and webpack-bundle-analyzer from required dependencies to optional peer dependencies in @rspack/cli, reducing the default dependency count from ~225 to ~2. The change adds runtime checks in the serve and preview commands to verify @rspack/dev-server is installed before use, providing clear error messages when missing.

Key Changes

  • Moved @rspack/dev-server and webpack-bundle-analyzer from dependencies to optional peer dependencies
  • Added package availability checks with helpful error messages in serve and preview commands
  • Updated lockfile to reflect dependency changes

Reviewed changes

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

File Description
packages/rspack-cli/package.json Moved two packages to optional peer dependencies, added peerDependenciesMeta configuration
pnpm-lock.yaml Updated to reflect packages moved from dependencies to devDependencies
packages/rspack-cli/src/commands/serve.ts Added check for @rspack/dev-server availability before use
packages/rspack-cli/src/commands/preview.ts Added check for @rspack/dev-server availability before use
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

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

"@rspack/core": "^1.0.0-alpha || ^1.x"
"@rspack/core": "^1.0.0-alpha || ^1.x",
"@rspack/dev-server": "~1.1.5",
"webpack-bundle-analyzer": "4.10.2"
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The version constraint for webpack-bundle-analyzer in peerDependencies uses an exact version (4.10.2) which is overly restrictive. Consider using a more flexible version range like "^4.10.2" to allow users to use newer compatible versions without peer dependency warnings. This follows the pattern used for @rspack/core which uses "^1.0.0-alpha || ^1.x".

Suggested change
"webpack-bundle-analyzer": "4.10.2"
"webpack-bundle-analyzer": "^4.10.2"

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

The previous contraint was fixed to 4.10.2, IMHO there is nothing to change here.

require.resolve(packageName);
} catch {
const logger = cli.getLogger();
logger.warn(
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The error message uses logger.warn but then exits with code 2, which indicates an error. Consider using logger.error instead of logger.warn for consistency, since this is a fatal error that prevents the command from running.

Suggested change
logger.warn(
logger.error(

Copilot uses AI. Check for mistakes.
require.resolve(packageName);
} catch {
const logger = cli.getLogger();
logger.warn(
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The error message uses logger.warn but then exits with code 2, which indicates an error. Consider using logger.error instead of logger.warn for consistency, since this is a fatal error that prevents the command from running.

Suggested change
logger.warn(
logger.error(

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +63
"@rspack/core": {
"optional": false
},
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

Setting "optional": false for @rspack/core in peerDependenciesMeta is redundant, as peer dependencies are required by default. You can remove this entry and only keep the entries for optional peer dependencies (@rspack/dev-server and webpack-bundle-analyzer).

Suggested change
"@rspack/core": {
"optional": false
},

Copilot uses AI. Check for mistakes.
@Kocal
Copy link
Author

Kocal commented Jan 8, 2026

I will apply Copilot comments after my work day

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! It's great to hear that Webpack Encore is considering replacing webpack with Rspack.

For this PR, it introduces a breaking change for existing users, so we're unable to merge it into the main branch.

We plan to remove the webpack-bundle-analyzer in the v2 branch, see: #9270 (comment).

As for @rspack/dev-server, making it a peer dependency is something we could consider. However, the vast majority of users rely on the dev server, and turning it into a peer dependency would likely increase the burden of dependency management for users. That said, this is something we could revisit in the v2 timeframe.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 8, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing Kocal:rspack-cli-peer-dependencies (7e42d29) with main (29642b2)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@Kocal
Copy link
Author

Kocal commented Jan 8, 2026

Hi, and thanks for your response.

For this PR, it introduces a breaking change for existing users, so we're unable to merge it into the main branch.

That's fully understandable, no problem.

We plan to remove the webpack-bundle-analyzer in the v2 branch, see: #9270 (comment).

Good news! 🤩

As for @rspack/dev-server, making it a peer dependency is something we could consider. However, the vast majority of users rely on the dev server, and turning it into a peer dependency would likely increase the burden of dependency management for users. That said, this is something we could revisit in the v2 timeframe.

Yeah the dev-server is actually super useful, but only during developpment.

Depending on the project, assets are built during application deployment (git push and a service like Heroku, Netlify, Coolify, ... will pull and build your app).
At this point, only the rspack build command is useful and used. All dependencies installed via the installation of @rspack/dev-server have only increased deployment time and are taking up unnecessary disk space.

the vast majority of users rely on the dev server, and turning it into a peer dependency would likely increase the burden of dependency management for users

That's true, if the dev-server become a peerDependency, people will have to install it manually through:

pnpm add @rspack/core @rspack/cli @rspack/dev-server -D

# or if you plan to run `pnpm install --prod` for deployment
pnpm add @rspack/core @rspack/cli 
pnpm add @rspack/dev-server -D

I will add a new message on #9270.

Should we close this PR for the moment?

@Kocal
Copy link
Author

Kocal commented Jan 8, 2026

Posted #9270 (comment)

I didn't try, but a workaround would be to configure packages resolutions and force @rspack/dev-server to be not installed in production.

This is easily doable with PNPM, if you are able to create this file before running pnpm install when deploying your app:

# pnpm-workspace.yaml
overrides:
  '@rspack/cli>@rspack/dev-server': link:node_modules/.ignored

@chenjiahan
Copy link
Member

Posted #9270 (comment)

Thanks! I will discuss with the team to determine whether to make @rspack/dev-server a peer dependency.

Should we close this PR for the moment?

I will close this PR now. Thank you again for your contribution. ❤️

@chenjiahan chenjiahan closed this Jan 9, 2026
@chenjiahan
Copy link
Member

Update:

@Kocal Kocal deleted the rspack-cli-peer-dependencies branch January 16, 2026 06:44
@Kocal
Copy link
Author

Kocal commented Jan 16, 2026

Oooh what a good news, thanks you @chenjiahan and @harpsealjs 😍

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

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments