feat(source-map): add extract option#7340
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Pull request overview
Adds an output.sourceMap.extract configuration namespace to enable Rspack’s rules[].extractSourceMap, allowing Rsbuild to preserve upstream JavaScript source maps (e.g. from packages shipping .js + .js.map).
Changes:
- Extend
output.sourceMapconfig/types/defaults with a newextractoption. - Apply
extractSourceMap: truevia a dedicated Rspack rule when extraction is enabled (with optional include/exclude filtering). - Add unit + e2e coverage and update docs/snapshots accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/en/config/output/source-map.mdx | Documents the new sourceMap.extract option and examples. |
| packages/core/src/types/config.ts | Adds public types for SourceMapExtract / SourceMapExtractTarget and wires extract into SourceMap. |
| packages/core/src/defaultConfig.ts | Sets output.sourceMap.extract default to false. |
| packages/core/src/plugins/sourceMap.ts | Implements extraction rule injection (extractSourceMap: true) with include/exclude support. |
| packages/core/src/index.ts | Re-exports the new types from the public entrypoint. |
| packages/core/tests/sourceMap.test.ts | Adds unit tests verifying rule injection + include/exclude normalization behavior. |
| packages/core/tests/snapshots/environments.test.ts.snap | Updates snapshots for the normalized environment config (extract: false). |
| e2e/cases/source-map/extract/src/index.js | New e2e entry importing a package intended to have upstream maps. |
| e2e/cases/source-map/extract/index.test.ts | New e2e assertions that upstream maps are preserved when extraction is enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Whether to extract source map from matching JavaScript files. | ||
| * `true` means extract from all files matched by the built-in JS rule. |
There was a problem hiding this comment.
Maybe we can add the extractSourceMap: true option to the built-in rule when extract is true, instead of creating a new rule.
There was a problem hiding this comment.
@chenjiahan Do you expect sourceMap.extract to follow the built-in SWC rule scope?
I kept it separate because the built-in JS rule handles transpilation and typically ignores node_modules, while extraction mainly targets upstream maps from dependencies
There was a problem hiding this comment.
That makes sense. A separate rule provides more flexibility when handling node_modules. 👍
There was a problem hiding this comment.
Pull request overview
Adds a new output.sourceMap.extract configuration namespace to enable extracting upstream JavaScript source maps (via Rspack rules[].extractSourceMap) so packages that ship .js + .js.map can preserve original mappings in the final output.
Changes:
- Extend
output.sourceMapconfig/type definitions to includeextract(boolean or{ js?: ... }) with defaultfalse. - Implement extraction rule injection in
plugin-source-mapby adding a dedicated Rspack rule withextractSourceMap: trueplus optionalinclude/exclude. - Add unit + e2e coverage and update environment normalization snapshots; document the new option.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| website/docs/en/config/output/source-map.mdx | Documents sourceMap.extract, updates type/default snippets, adds usage examples. |
| packages/core/tests/sourceMap.test.ts | Unit tests to assert extract rules are added/normalized correctly. |
| packages/core/tests/snapshots/environments.test.ts.snap | Snapshot updates for normalized sourceMap.extract: false. |
| packages/core/src/types/config.ts | Introduces SourceMapExtract* types and wires extract into SourceMap / normalized output config. |
| packages/core/src/plugins/sourceMap.ts | Adds pre-chain handler to inject extractSourceMap rule for JS with include/exclude support. |
| packages/core/src/index.ts | Exports SourceMapExtract and SourceMapExtractTarget as public types. |
| packages/core/src/defaultConfig.ts | Adds sourceMap.extract: false to default normalized output config. |
| e2e/cases/source-map/extract/src/index.js | New e2e fixture consuming a package with an upstream sourcemap. |
| e2e/cases/source-map/extract/index.test.ts | E2E test validating upstream sourcemaps are preserved when extraction is enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
extract option
|
@chenjiahan Hi! I didn't expect this to merge so quickly, as I'm unsure if this configuration scheme is the best we can get. Also, since we can't change the "test" property for the rule itself, do you have any ideas on how we can do this properly? CRA (outdated, but whatever) uses |
Summary
Adds a
output.sourceMap.extractoption, so Rspack'srules[].extractSourceMapcan be enabled.This implementation supports JS extraction only. I considered CSS extraction as well, but the current CSS pipeline does not preserve upstream CSS source maps end to end. Keeping
sourceMap.extractas its own namespace still gives a clear place to support CSS in the future if that becomes possible.Related Links
Checklist