srcmap-remapping
Source map concatenation and composition/remapping for Rust.
Merges or chains source maps from multiple build steps into a single map. Drop-in Rust equivalent of @ampproject/remapping.
Install
[]
= "0.1"
Usage
Concatenation
Merge source maps from multiple bundled files into one, adjusting line offsets. Used by bundlers (esbuild, Rollup, Webpack).
use ConcatBuilder;
use SourceMap;
let map_a = from_json.unwrap;
let map_b = from_json.unwrap;
let mut builder = new;
builder.add_map; // a.js starts at line 0
builder.add_map; // b.js starts at line 100
let result = builder.build;
Composition / Remapping
Chain source maps through multiple transforms (e.g. TypeScript -> JavaScript -> minified) into a single map pointing to the original sources.
use remap;
use SourceMap;
let minified_map = from_json.unwrap;
let result = remap;
// result now maps minified output directly to TypeScript sources
API
Concatenation
| Method | Description |
|---|---|
ConcatBuilder::new(file) -> Self |
Create a new concatenation builder |
builder.add_map(sourcemap, line_offset) |
Add a source map at the given line offset |
builder.build() -> SourceMap |
Finish and return the concatenated source map |
builder.to_json() -> String |
Finish and return as JSON string |
Composition
| Function | Description |
|---|---|
remap(outer, loader) -> SourceMap |
Compose through upstream maps resolved by loader |
The loader function receives each source filename and returns Option<SourceMap>. Return Some to trace through an upstream map, or None to keep the source as-is.
Features
- Source and name deduplication across concatenated maps
sourcesContentmerging from all inputsignoreListpropagation through concatenation- Name resolution prefers upstream names over outer names
- Lazy loading via the
loadercallback — only loads maps that are actually referenced
Part of srcmap
See also:
srcmap-sourcemap- Parser and consumersrcmap-generator- Source map buildersrcmap-codec- VLQ encode/decode
License
MIT