feat!: default resolve roots to empty array#13273
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Rspack’s default resolve.roots behavior to no longer implicitly include the compilation context, aligning the default to an empty list and adjusting tests/cases accordingly.
Changes:
- Change JS/TS defaults so
resolve.rootsdefaults to[]instead of[context]. - Change Rust builder defaults so
rootsis an empty list by default as well. - Update defaults snapshots and the
resolve/rootsconfig case to explicitly setresolve.rootswhen needed.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rspack-test/defaultsCases/default/base.js | Updates the defaults snapshot to expect resolve.roots: []. |
| tests/rspack-test/defaultsCases/config/browserslist.js | Updates an inline diff snapshot (notably context/uniqueName lines). |
| tests/rspack-test/configCases/resolve/roots/rspack.config.js | Explicitly sets resolve.roots for the /dir/* resolution test case. |
| packages/rspack/src/config/types.ts | Removes outdated doc text implying roots defaults to context. |
| packages/rspack/src/config/defaults.ts | Drops context from resolve defaults computation and sets default roots: []. |
| crates/rspack/src/builder/mod.rs | Updates Rust-side resolve defaults to use empty roots. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🙈 Size remains the same at 49.11MB |
Merging this PR will not alter performance
Comparing Footnotes
|
chenjiahan
left a comment
There was a problem hiding this comment.
Could you update the documentation too?
Deploying rspack with
|
| Latest commit: |
9e8222c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f93f446a.rspack-v2.pages.dev |
| Branch Preview URL: | https://feat-roots-2.rspack-v2.pages.dev |
Summary
Breaking Change:
resolve.rootsdefaults to[]Before:
resolve.rootsdefaulted to[context], mirroring webpack's behavior.After:
resolve.rootsdefaults to[].Motivation
When resolving an absolute path specifier (e.g.,
/Users/foo/bar/baz.ts), rspack-resolver firstprobes each entry in
rootsby joining it with the specifier — soroots: [context]causes Nfilesystem
statcalls on paths like{context}/Users/foo/bar/...before falling through to thecorrect absolute path resolution. This is pure IO waste for the common case where an absolute path
is meant to be exactly that.
Server-relative URL resolution (e.g., importing
'/static/app.js'and expecting it to resolverelative to the project root) is a narrow use case. Making
roots: [context]the default imposesunnecessary overhead on every project that never uses this feature.
Migration
If you rely on server-relative URL resolution, explicitly restore the previous behavior:
Related links
Checklist