Skip to content

Commit 4d5eb08

Browse files
sokraskipjack
authored andcommitted
docs(config): improve devtool documentation (#1533)
Elaborate on the `devtool` options and explain in more detail how each one affects the output source mapping and compilation speed. fixes #273 fixes webpack/webpack#2725 fixes webpack/webpack#4936 fixes webpack/webpack#2766 fixes webpack/webpack#2145 fixes webpack/webpack#1689
1 parent ddb32f2 commit 4d5eb08

File tree

1 file changed

+61
-23
lines changed

1 file changed

+61
-23
lines changed

src/content/configuration/devtool.md

+61-23
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,91 @@ Choose a style of [source mapping](http://blog.teamtreehouse.com/introduction-so
2626

2727
T> The webpack repository contains an [example showing the effect of all `devtool` variants](https://github.com/webpack/webpack/tree/master/examples/source-map). Those examples will likely help you to understand the differences.
2828

29-
devtool | build | rebuild | production | quality
30-
----------------------------- | ----- | ------- | ---------- | -----------------------------
31-
eval | +++ | +++ | no | generated code
32-
cheap-eval-source-map | + | ++ | no | transformed code (lines only)
33-
cheap-source-map | + | o | yes | transformed code (lines only)
34-
cheap-module-eval-source-map | o | ++ | no | original source (lines only)
35-
cheap-module-source-map | o | - | yes | original source (lines only)
36-
eval-source-map | -- | + | no | original source
37-
source-map | -- | -- | yes | original source
38-
inline-source-map | -- | -- | no | original source
39-
hidden-source-map | -- | -- | yes | original source
40-
nosources-source-map | -- | -- | yes | without source content
41-
42-
T> `+` means faster, `-` slower and `o` about the same time
43-
44-
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.
29+
T> Instead of using the `devtool` option you can also use `SourceMapDevToolPlugin`/`EvalSourceMapDevToolPlugin` directly as it has more options. Never use both the `devtool` option and plugin together. The `devtool` option adds the plugin internally so you would end up with the plugin applied twice.
30+
31+
devtool | build | rebuild | production | quality
32+
------------------------------ | ----- | ------- | ---------- | -----------------------------
33+
(none) | +++ | +++ | no | bundled code
34+
eval | +++ | +++ | no | generated code
35+
cheap-eval-source-map | + | ++ | no | transformed code (lines only)
36+
cheap-module-eval-source-map | o | ++ | no | original source (lines only)
37+
eval-source-map | -- | + | no | original source
38+
cheap-source-map | + | o | no | transformed code (lines only)
39+
cheap-module-source-map | o | - | no | original source (lines only)
40+
inline-cheap-source-map | + | o | no | transformed code (lines only)
41+
inline-cheap-module-source-map | o | - | no | original source (lines only)
42+
source-map | -- | -- | yes | original source
43+
inline-source-map | -- | -- | no | original source
44+
hidden-source-map | -- | -- | yes | original source
45+
nosources-source-map | -- | -- | yes | without source content
46+
47+
T> `+++` super fast, `++` fast, `+` pretty fast, `o` medium, `-` pretty slow, `--` slow
48+
49+
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.
4550

4651
W> There are some issues with Source Maps in Chrome. [We need your help!](https://github.com/webpack/webpack/issues/3165).
4752

4853
T> See [`output.sourceMapFilename`](/configuration/output#output-sourcemapfilename) to customize the filenames of generated Source Maps.
4954

5055

56+
### Qualities
57+
58+
`bundled code` - You see all generated code as a big blob of code. You don't see modules separated from each other.
59+
60+
`generated code` - You see each module separated from each other, annotated with module names. You see the code generated by webpack. Example: Instead of `import {test} from "module"; test();` you see something like `var module__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(42); module__WEBPACK_IMPORTED_MODULE_1__.a();`.
61+
62+
`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 of `import {test} from "module"; class A extends test {}` you see something like `import {test} from "module"; var A = function(_test) { ... }(test);`
63+
64+
`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.
65+
66+
`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 set [`output.devtoolModuleFilenameTemplate`](/configuration/output/#output-devtoolmodulefilenametemplate) correctly to match source urls.
67+
68+
`(lines only)` - Source Maps are simplified to a single mapping per line. This usually means a single mapping per statement (assuming you author is 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.
69+
70+
5171
### Development
5272

5373
The following options are ideal for development:
5474

55-
`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.
75+
`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).
76+
77+
`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.
78+
79+
`cheap-eval-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.
80+
81+
`cheap-module-eval-source-map` - Similar to `cheap-eval-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.
82+
83+
### Special cases
84+
85+
The following options are not ideal for development nor production. They are needed for some special cases, i. e. for some 3rd party tools.
5686

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

59-
`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.
89+
`cheap-source-map` - A SourceMap without column-mappings ignoring loader Source Maps.
6090

61-
`cheap-eval-source-map` - Similar to `eval-source-map`, each module is executed with `eval()`. However, with this option the Source Map is passed as a Data URL to the `eval()` call. It is "cheap" because it doesn't have column mappings, it only maps line numbers.
91+
`inline-cheap-source-map` - Similar to `cheap-source-map` but SourceMap is added as a DataUrl to the bundle.
6292

63-
`cheap-module-eval-source-map` - Similar to `cheap-eval-source-map`, however, in this case loaders are able to process the mapping for better results.
93+
`cheap-module-source-map` - A SourceMap without column-mappings that simplifies loader Source Maps to a single mapping per line.
94+
95+
`inline-cheap-module-source-map` - Similar to `cheap-module-source-map` but SourceMap is added as a DataUrl to the bundle.
6496

6597

6698
### Production
6799

68100
These options are typically used in production:
69101

102+
`(none)` (Omit the `devtool` option) - No SourceMap is emitted. This is a good option to start with.
103+
70104
`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.
71105

106+
W> You should configure your server to disallow access to the Source Map file for normal users!
107+
72108
`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.
73109

74-
`cheap-source-map` - A SourceMap without column-mappings ignoring loaded Source Maps.
110+
W> You should not deploy the Source Map file to the webserver. Instead only use it for error report tooling.
111+
112+
`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.
75113

76-
`cheap-module-source-map` - A SourceMap without column-mappings that simplifies loaded Source Maps to a single mapping per line.
114+
W> It still exposes filenames and structure for decompiling, but it doesn't expose the original code.
77115

78-
`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.
116+
T> When using the `uglifyjs-webpack-plugin` you must provide the `sourceMap: true` option to enable SourceMap support.

0 commit comments

Comments
 (0)