What a source map is
A source map is a JSON file that lets debuggers translate positions in generated
(minified, transpiled, or bundled) code back to positions in your original
source. The current format is Source Map v3. Its most important and most
cryptic field is mappings: a compact, base64 VLQ-encoded string that pairs
every span of generated output with the original file, line, column, and name it
came from.
How it works
The JSON has a small, fixed set of top-level fields — version, sources,
names, mappings, and a few optional helpers. The mappings string is read as
follows:
- A
;advances to the next line of generated code (the generated column counter resets to 0). - A
,separates segments within a line. - Each segment is 1, 4, or 5 VLQ values: generated column, then source index,
original line, original column, and optionally a
namesindex. - Every value except the generated column-at-start is a delta from the previous occurrence, which keeps the numbers — and so the string — tiny.
The reference lists each field; the decoder below expands a single segment’s base64 VLQ values into plain integers so you can see the mechanism.
Tips and notes
version must be 3 — anything else means a tool will refuse the map. Keep
sources paths consistent and use sourceRoot to factor out a common prefix.
Inline sourcesContent when the originals may not be reachable at debug time.
The map is located via a //# sourceMappingURL= comment or a SourceMap
response header; never ship the comment to production if you do not want maps
discoverable.