feat(@rspack-cli): make @rspack/dev-server and webpack-bundle-analyzer peer dependencies#12682
feat(@rspack-cli): make @rspack/dev-server and webpack-bundle-analyzer peer dependencies#12682Kocal wants to merge 1 commit intoweb-infra-dev:mainfrom
Conversation
…r peer dependencies
✅ Deploy Preview for rspack ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
| "@rspack/core": { | ||
| "optional": false | ||
| }, |
There was a problem hiding this comment.
@rspack/core was already a peerDependency but it was not explicitly configured as non-optional.
There was a problem hiding this comment.
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-serverandwebpack-bundle-analyzerfrom dependencies to optional peer dependencies - Added package availability checks with helpful error messages in
serveandpreviewcommands - 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" |
There was a problem hiding this comment.
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".
| "webpack-bundle-analyzer": "4.10.2" | |
| "webpack-bundle-analyzer": "^4.10.2" |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
| logger.warn( | |
| logger.error( |
| require.resolve(packageName); | ||
| } catch { | ||
| const logger = cli.getLogger(); | ||
| logger.warn( |
There was a problem hiding this comment.
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.
| logger.warn( | |
| logger.error( |
| "@rspack/core": { | ||
| "optional": false | ||
| }, |
There was a problem hiding this comment.
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).
| "@rspack/core": { | |
| "optional": false | |
| }, |
|
I will apply Copilot comments after my work day |
chenjiahan
left a comment
There was a problem hiding this comment.
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 Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
|
Hi, and thanks for your response.
That's fully understandable, no problem.
Good news! 🤩
Yeah the dev-server is actually super useful, but only during developpment. Depending on the project, assets are built during application deployment (
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 -DI will add a new message on #9270. Should we close this PR for the moment? |
|
Posted #9270 (comment) I didn't try, but a workaround would be to configure packages resolutions and force This is easily doable with PNPM, if you are able to create this file before running # pnpm-workspace.yaml
overrides:
'@rspack/cli>@rspack/dev-server': link:node_modules/.ignored |
Thanks! I will discuss with the team to determine whether to make
I will close this PR now. Thank you again for your contribution. ❤️ |
|
Update:
|
|
Oooh what a good news, thanks you @chenjiahan and @harpsealjs 😍 |
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-serveran 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-serveris only useful when runningrspack serve, and not all projects need it. Based on @rspack/dev-server's npmgraph, it brings ~207 dependencies,webpack-bundle-analyzeris only useful when runningrspack analyze, and not all projects need it. Based on webpack-bundle-analyzer's npmgraph, it brings ~16 dependenciesBy making these two dependencies optional, we could reduce the number of dependencies to 2 (
@discoveryjs/json-extandwebpack-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 serveorrspack analyze.WDYT? Thanks!
Related links
Checklist
[ ] Tests updated (or not required).