Source Maps in Production
You'll learn: How to decide whether and how to deploy source maps in production environments.
The Production Dilemma
When your application reaches production, source maps become a double-edged sword. They're invaluable for debugging real-world errors, but they also expose your original source code to anyone who opens DevTools. You have three main strategies:
1. Ship Publicly
Upload source maps alongside your bundled code. Anyone can download them and see your original source. This is simplest but exposes your code completely.
When to use: Open-source projects, internal tools, or when code protection isn't a concern.
2. Conditional Serving
Host source maps but restrict access. You might:
- Require authentication headers
- IP-whitelist your office/VPN
- Serve maps only to logged-in users with special permissions
When to use: When you need debugging flexibility but want some access control.
3. Private Upload to Error Trackers
Upload source maps directly to services like Sentry, Rollbar, or Bugsnag—never to your public server. These tools use them to de-minify stack traces in their dashboards, but users never see the maps.
When to use: Most commercial applications. You get excellent debugging while keeping source code private.
Making the Choice
Think of it like a restaurant kitchen: fully public (open kitchen), conditionally visible (peek through a window with permission), or completely private (send error reports to the chef, who has the recipe book).
Most teams choose option 3: remove the sourceMappingURL comment from production bundles and upload maps to their error tracker using build-time plugins. You get symbolicated stack traces without exposing code.
Key Takeaway: In production, either upload source maps privately to error tracking services or serve them conditionally behind authentication—rarely ship them publicly unless your code is already open-source.