Movatterモバイル変換


[0]ホーム

URL:


webpack logo
ag grid
ag charts

Devtool

This option controls if and how source maps are generated.Use theSourceMapDevToolPlugin for a more fine grained configuration. See theRule.extractSourceMap to deal with existing source maps.

devtool

string = 'eval'Array<{ type: "all" | "javascript" | "css", use: string }>false

Choose a style ofsource mapping to enhance the debugging process. These values can affect build and rebuild speed dramatically.

5.105.0+

You can also provide an array of objects to configure different source map styles for different asset types:

webpack.config.js

module.exports={// ...  devtool:[{ type:"javascript", use:"source-map"},{ type:"css", use:"inline-source-map"},],};

Thetype field specifies which asset type should receive the devtool value:

  • "all" - applies to all asset types (JavaScript and CSS)
  • "javascript" - applies only to JavaScript files
  • "css" - applies only to CSS files

When using an array, each entry will be processed in order. If you provide a string value, it will be treated as{ type: "all", use: "your-string-value" }.

tip

The webpack repository contains anexample showing the effect of alldevtool variants. Those examples will likely help you to understand the differences.

tip

Instead of using thedevtool option you can also useSourceMapDevToolPlugin/EvalSourceMapDevToolPlugin directly as it has more options. Never use both thedevtool option and plugin together. Thedevtool option adds the plugin internally so you would end up with the plugin applied twice.

devtoolperformanceproductionqualitycomment
(none)build: fastest

rebuild: fastest
yesbundleRecommended choice for production builds with maximum performance.
evalbuild: fast

rebuild: fastest
nogeneratedRecommended choice for development builds with maximum performance.
eval-cheap-source-mapbuild: ok

rebuild: fast
notransformedTradeoff choice for development builds.
eval-cheap-module-source-mapbuild: slow

rebuild: fast
nooriginal linesTradeoff choice for development builds.
eval-source-mapbuild: slowest

rebuild: ok
nooriginalRecommended choice for development builds with high quality SourceMaps.
cheap-source-mapbuild: ok

rebuild: slow
notransformed-
cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal lines-
source-mapbuild: slowest

rebuild: slowest
yesoriginalRecommended choice for production builds with high quality SourceMaps.
inline-cheap-source-mapbuild: ok

rebuild: slow
notransformed-
inline-cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal lines-
inline-source-mapbuild: slowest

rebuild: slowest
nooriginalPossible choice when publishing a single file
eval-nosources-cheap-source-mapbuild: ok

rebuild: fast
notransformedsource code not included
eval-nosources-cheap-module-source-mapbuild: slow

rebuild: fast
nooriginal linessource code not included
eval-nosources-source-mapbuild: slowest

rebuild: ok
nooriginalsource code not included
inline-nosources-cheap-source-mapbuild: ok

rebuild: slow
notransformedsource code not included
inline-nosources-cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal linessource code not included
inline-nosources-source-mapbuild: slowest

rebuild: slowest
nooriginalsource code not included
nosources-cheap-source-mapbuild: ok

rebuild: slow
notransformedsource code not included
nosources-cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal linessource code not included
nosources-source-mapbuild: slowest

rebuild: slowest
yesoriginalsource code not included
hidden-nosources-cheap-source-mapbuild: ok

rebuild: slow
notransformedno reference, source code not included
hidden-nosources-cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal linesno reference, source code not included
hidden-nosources-source-mapbuild: slowest

rebuild: slowest
yesoriginalno reference, source code not included
hidden-cheap-source-mapbuild: ok

rebuild: slow
notransformedno reference
hidden-cheap-module-source-mapbuild: slow

rebuild: slow
nooriginal linesno reference
hidden-source-mapbuild: slowest

rebuild: slowest
yesoriginalno reference. Possible choice when using SourceMap only for error reporting purposes.
shortcutexplanation
performance: buildHow is the performance of the initial build affected by the devtool setting?
performance: rebuildHow is the performance of the incremental build affected by the devtool setting? Slow devtools might reduce development feedback loop in watch mode. The scale is different compared to the build performance, as one would expect rebuilds to be faster than builds.
productionDoes it make sense to use this devtool for production builds? It's usuallyno when the devtool has a negative effect on user experience.
quality: bundledYou will see all generated code of a chunk in a single blob of code. This is the raw output file without any devtooling support
quality: generatedYou will see the generated code, but each module is shown as separate code file in browser devtools.
quality: transformedYou will see generated code after the preprocessing by loaders but before additional webpack transformations. Only source lines will be mapped and column information will be discarded resp. not generated. This prevents setting breakpoints in the middle of lines which doesn't work together with minimizer.
quality: original linesYou will see the original code that you wrote, assuming all loaders support SourceMapping. Only source lines will be mapped and column information will be discarded resp. not generated. This prevents setting breakpoints in the middle of lines which doesn't work together with minimizer.
quality: originalYou will see the original code that you wrote, assuming all loaders support SourceMapping.
eval-* additiongenerate SourceMap per module and attach it via eval. Recommended for development, because of improved rebuild performance. Note that there is a windows defender issue, which causes huge slowdown due to virus scanning.
inline-* additioninline the SourceMap to the original file instead of creating a separate file.
hidden-* additionno reference to the SourceMap added. When SourceMap is not deployed, but should still be generated, e. g. for error reporting purposes.
nosources-* additionsource code is not included in SourceMap. This can be useful when the original files should be referenced (further config options needed).
tip

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.

Some of these values are suited for development and some for production. For development you typically want fast Source Maps at the cost of bundle size, but for production you want separate Source Maps that are accurate and support minimizing.

tip

Seeoutput.sourceMapFilename to customize the filenames of generated Source Maps.

Qualities

bundled code - You see all generated code as a big blob of code. You don't see modules separated from each other.

generated code - You see each module separated from each other, annotated with module names. You see the code generated by webpack. Example: Instead ofimport {test} from "module"; test(); you see something likevar module__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(42); module__WEBPACK_IMPORTED_MODULE_1__.a();.

transformed code - You see each module separated from each other, annotated with module names. You see the code before webpack transforms it, but after Loaders transpile it. Example: Instead ofimport {test} from "module"; class A extends test {} you see something likeimport {test} from "module"; var A = function(_test) { ... }(test);

original source - You see each module separated from each other, annotated with module names. You see the code before transpilation, as you authored it. This depends on Loader support.

without source content - Contents for the sources are not included in the Source Maps. Browsers usually try to load the source from the webserver or filesystem. You have to make sure to setoutput.devtoolModuleFilenameTemplate correctly to match source urls.

(lines only) - Source Maps are simplified to a single mapping per line. This usually means a single mapping per statement (assuming you author it this way). This prevents you from debugging execution on statement level and from settings breakpoints on columns of a line. Combining with minimizing is not possible as minimizers usually only emit a single line.

Development

The following options are ideal for development:

eval - Each module is executed witheval() 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 witheval() and a SourceMap is added as a DataUrl to theeval(). 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 toeval-source-map, each module is executed witheval(). 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 theeval devtool.

eval-cheap-module-source-map - Similar toeval-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.

Special cases

The following options are not ideal for development nor production. They are needed for some special cases, i. e. for some 3rd party tools.

inline-source-map - A SourceMap is added as a DataUrl to the bundle.

cheap-source-map - A SourceMap without column-mappings ignoring loader Source Maps.

inline-cheap-source-map - Similar tocheap-source-map but SourceMap is added as a DataUrl to the bundle.

cheap-module-source-map - A SourceMap without column-mappings that simplifies loader Source Maps to a single mapping per line.

inline-cheap-module-source-map - Similar tocheap-module-source-map but SourceMap is added as a DataUrl to the bundle.

Production

These options are typically used in production:

(none) (Omit thedevtool option or setdevtool: 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.

warning

You should configure your server to disallow access to the Source Map file for normal users!

hidden-source-map - Same assource-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.

warning

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 thesourcesContent 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.

warning

It still exposes filenames and structure for decompiling, but it doesn't expose the original code.

tip

If the default webpackminimizer has been overridden (such as to customise theterser-webpack-plugin options), make sure to configure its replacement withsourceMap: true to enable SourceMap support.

« Previous
Cache
Next »
Extends

8 Contributors

sokraskipjackSpaceK33zlricoymadhavarshneywizardofhogwartsanikethsahasnitin315

[8]ページ先頭

©2009-2026 Movatter.jp