Configuring Source Maps in Bundlers
You'll learn how to enable and configure source maps across different JavaScript bundlers.
Now that you understand source map types and quality levels, it's time to actually tell your bundler to generate them. Each bundler has its own configuration syntax, but they all control the same underlying behavior: what kind of source map to produce (if any) and where to put it.
Core Idea
Think of source map configuration as choosing your camera's resolution and where to save photos. Different projects need different settings—during development you want maximum detail (even if the files are huge), while in production you might want smaller files or no maps at all.
Webpack Configuration
In webpack, use the devtool option:
// webpack.config.js
module.exports = {
devtool: 'source-map', // Full external source map
// OR
// devtool: 'eval-source-map', // Inline, fast rebuilds
// devtool: 'cheap-module-source-map', // Faster, less precise
};
Rollup Configuration
In Rollup, enable sourcemap in the output options:
// rollup.config.js
export default {
output: {
sourcemap: true, // or 'inline' for inline maps
file: 'bundle.js'
}
};
Vite Configuration
Vite controls source maps through build.sourcemap:
// vite.config.js
export default {
build: {
sourcemap: true, // or 'inline' or 'hidden'
}
};
Environment-Specific Settings
Commonly, you'll want different settings for development vs production—detailed maps locally, hidden or disabled maps in production to protect source code.
Key Takeaway: Every bundler provides a configuration option to control source map generation; set devtool in webpack, sourcemap in Rollup, or equivalent options in other tools to match your debugging needs and deployment constraints.