The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Choose a style of source mapping to enhance the debugging process. These values can affect build and rebuild speed dramatically.
Use the SourceMapDevToolPlugin or EvalSourceMapDevToolPlugin for a more fine grained configuration.
eval
devtool: false
devtool: 'eval'
eval()
with //# sourceURL
commentSet devtool: 'source-map'
, A full SourceMap is emitted as a separate file. It adds a //# sourceMapURL
comment to the bundle so development tools know where to find it.
It also supports combination with the following modifiers to improve performance and control SourceMap generation.
Performance optimization modifiers, to speed up the build, usually used in development environments:
Modifier | Effect | Performance improvement |
---|---|---|
eval | Each module is executed with eval() and a SourceMap is added as a DataUrl to the eval() , avoiding chunk-level multiple SourceMap concate |
⚡⚡⚡ |
cheap | Maps line numbers only (no columns), ignores source maps from loaders | ⚡⚡ |
module | Processes source maps from loaders to map to original code (line-only mapping) | ⚡ |
Functional modifiers, to control SourceMap generation, usually used in production environments:
Modifier | Effect |
---|---|
hidden | SourceMap is emitted as a separate file, but no //# sourceMappingURL=[url] comment is added to the bundle, protecting source code privacy |
inline | SourceMap is added as a DataUrl to the bundle |
nosources | SourceMap is created without the sourcesContent in it |
debugids | SourceMap is created with the debugId in it |
We expect a certain pattern when validate devtool name, pay attention and don't mix up the sequence of devtool string. The pattern is: [inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map[-debugids]
.
The following options are ideal for development:
eval
- Each module is executed with eval()
and //# sourceURL
. This is pretty fast. The main disadvantage is that it doesn't display line numbers correctly since it gets mapped to transpiled code instead of the original code (No Source Maps from Loaders).
eval-source-map
- Each module is executed with eval()
and a SourceMap is added as a DataUrl to the eval()
. Initially it is slow, but it provides fast rebuild speed and yields real files. Line numbers are correctly mapped since it gets mapped to the original code. It yields the best quality SourceMaps for development.
eval-cheap-source-map
- Similar to eval-source-map
, each module is executed with eval()
. It is "cheap" because it doesn't have column mappings, it only maps line numbers. It ignores SourceMaps from Loaders and only display transpiled code similar to the eval devtool.
eval-cheap-module-source-map
- Similar to eval-cheap-source-map
, however, in this case Source Maps from Loaders are processed for better results. However Loader Source Maps are simplified to a single mapping per line.
These options are typically used in production:
'false' - No SourceMap is emitted. This is a good option to start with.
source-map
- A full SourceMap is emitted as a separate file. It adds a reference comment to the bundle so development tools know where to find it.
You should configure your server to disallow access to the Source Map file for normal users!
hidden-source-map
- Same as source-map
, but doesn't add a reference comment to the bundle. Useful if you only want SourceMaps to map error stack traces from error reports, but don't want to expose your SourceMap for the browser development tools.
You should not deploy the Source Map file to the webserver. Instead only use it for error report tooling.
nosources-source-map
- A SourceMap is created without the sourcesContent
in it. It can be used to map stack traces on the client without exposing all of the source code. You can deploy the Source Map file to the webserver.
It still exposes original filenames and structure, but it doesn't expose the original code.