devtool option controls if and how source maps are generated. Source maps provide a way to map minified/compiled code back to the original source code for debugging.
Basic Configuration
webpack.config.js
DevTool Option
Choose a style of source mapping.Set to
false to disable source maps.Source Map Types
Production
Recommended for production builds:source-map (Recommended for Production)
source-map (Recommended for Production)
Full source map as a separate file.
- Quality: Original source
- Build: Slowest
- Rebuild: Slowest
- Production: Yes
- File: Separate
.mapfile
hidden-source-map
hidden-source-map
nosources-source-map
nosources-source-map
Source map without the source content.
- Quality: Only line numbers
- Build: Slowest
- Rebuild: Slowest
- Production: Yes
- File: Separate
.mapfile
Development
Recommended for development builds:eval-source-map (Recommended for Development)
eval-source-map (Recommended for Development)
Each module is executed with
eval() with a source map.- Quality: Original source
- Build: Slowest
- Rebuild: Fast
- Production: No
- File: Inline
eval-cheap-source-map
eval-cheap-source-map
Similar to
eval-source-map, each module is executed with eval() but with lower quality.- Quality: Transformed code (loader output)
- Build: Fast
- Rebuild: Fast
- Production: No
- File: Inline
eval-cheap-module-source-map
eval-cheap-module-source-map
Like
eval-cheap-source-map but with better quality.- Quality: Original source (loader input)
- Build: Medium
- Rebuild: Fast
- Production: No
- File: Inline
eval
eval
Each module is executed with
eval() without source map.- Quality: Generated code
- Build: Fastest
- Rebuild: Fastest
- Production: No
- File: None
Other Options
inline-source-map
inline-source-map
Source map as a DataUrl in the bundle.
- Quality: Original source
- Build: Slowest
- Rebuild: Slowest
- Production: No
- File: Inline DataUrl
cheap-source-map
cheap-source-map
Source map without column mappings.
- Quality: Transformed code
- Build: Fast
- Rebuild: Medium
- Production: No
- File: Separate
.mapfile
cheap-module-source-map
cheap-module-source-map
Source map without column mappings from original source.
- Quality: Original source
- Build: Medium
- Rebuild: Medium
- Production: No
- File: Separate
.mapfile
Source Map Naming
Source map options follow this naming pattern:- inline: Embed source map as DataUrl
- hidden: Generate source map but don’t reference it
- eval: Wrap modules in
eval()(fast rebuilds) - nosources: Exclude source content (only stack traces)
- cheap: Line-only mapping (no columns)
- module: Map to original source (before loaders)
Configuration by Environment
Production Configuration
webpack.prod.js
Development Configuration
webpack.dev.js
Conditional Configuration
webpack.config.js
Source Map Output
Customize source map filename.Default:
'[file].map[query]'Customize module filenames in source maps.
Module namespace in source maps.
Asset-Specific Source Maps
Webpack 5 allows different devtools per asset type:webpack.config.js
Performance Comparison
| devtool | build | rebuild | production | quality |
|---|---|---|---|---|
| (none) | fastest | fastest | yes | bundle |
| eval | fastest | fastest | no | generated |
| eval-cheap-source-map | fast | fast | no | transformed |
| eval-cheap-module-source-map | medium | fast | no | original lines |
| eval-source-map | slowest | fast | no | original |
| cheap-source-map | fast | medium | no | transformed |
| cheap-module-source-map | medium | medium | no | original lines |
| source-map | slowest | slowest | yes | original |
| inline-source-map | slowest | slowest | no | original |
| hidden-source-map | slowest | slowest | yes | original |
| nosources-source-map | slowest | slowest | yes | no source |
Best Practices
Recommended Settings
Error Monitoring Integration
For services like Sentry:webpack.config.js
TypeScript Configuration
For TypeScript projects, also configuretsconfig.json:
tsconfig.json
CSS Source Maps
Enable source maps in CSS loaders:webpack.config.js
Disable Source Maps
webpack.config.js
Common Patterns
Multi-Environment Setup
webpack.config.js
Conditional Source Maps
webpack.config.js
Docker/Container Builds
webpack.config.js