Skip to content
BENIBIX Learn

Source Map

Development🌐 Web DevelopmentBuild Tools

Also known as Sourcemap, .map file

A file that links shrunk, built code back to the code you wrote.

Think of it like

Think of it like a key on a treasure map. It tells you which squiggle on the page is which real place.

Example

An error says line 1, column 48,213 of app.min.js. With the source map, the browser shows it is line 12 of cart.ts.

Why it matters

It makes errors in real sites readable. Debugging without one is guesswork.

Definition

A source map is a file that links built, shrunk code back to the original source you wrote. When an error happens in the bundle, the browser's tools use the map to show your real file and line. Without one, you would see one giant line of minified code. Build tools write the map next to each bundle. The bundle points to it with a comment at the end.

Example code

javascript
//# sourceMappingURL=app.min.js.map
The last line of a bundle points to its source map.

Common mistake

Publishing source maps when your code is meant to stay private. They let anyone read the original.

Key takeaways

  1. 1
    Built to original. Links shrunk code to yours.
  2. 2
    Readable errors. Real file and line numbers.
  3. 3
    Think before you publish. It exposes your source.