Skip to content

Commit a4bdaa2

Browse files
EugeneHlushkoskipjack
authored andcommitted
docs(plugins): update the source-map-devtool-plugin (#1707)
Clean up formatting a bit and add undocumented options from webpack/webpack#5986. Update the external source maps example to demonstrate path stripping.
1 parent 3d3ab97 commit a4bdaa2

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/content/plugins/source-map-dev-tool-plugin.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ related:
1010

1111
This plugin enables more fine grained control of source map generation. It is an alternative to the [`devtool`](/configuration/devtool/) configuration option.
1212

13-
```javascript
13+
``` js
1414
new webpack.SourceMapDevToolPlugin(options)
1515
```
1616

@@ -28,20 +28,26 @@ The following options are supported:
2828
- `fallbackModuleFilenameTemplate` (`string`): See link above.
2929
- `module` (`boolean`): Indicates whether loaders should generate source maps (defaults to `true`).
3030
- `columns` (`boolean`): Indicates whether column mappings should be used (defaults to `true`).
31-
- `lineToLine` (`object`): Simplify and speed up source mapping by using line to line source mappings for matched modules.**
31+
- `lineToLine` (`object`): Simplify and speed up source mapping by using line to line source mappings for matched modules.
32+
- `publicPath` (`string`): Emits absolute URLs with public path prefix, e.g. `https://example.com/project/`.
33+
- `fileContext` (`string`): Makes the `[file]` argument relative to this directory.
3234

3335
The `lineToLine` object allows for the same `test`, `include`, and `exclude` options described above.
3436

37+
The `fileContext` option is useful when you want to store source maps in an upper level directory to avoid `../../` appearing in the absolute `[url]`.
38+
3539
T> Setting `module` and/or `columns` to `false` will yield less accurate source maps but will also improve compilation performance significantly.
3640

3741

3842
## Examples
3943

44+
The following examples demonstrate some common use cases for this plugin.
45+
4046
### Exclude Vendor Maps
4147

4248
The following code would exclude source maps for any modules in the `vendor.js` bundle:
4349

44-
```javascript
50+
``` js
4551
new webpack.SourceMapDevToolPlugin({
4652
filename: '[name].js.map',
4753
exclude: ['vendor.js']
@@ -52,9 +58,36 @@ new webpack.SourceMapDevToolPlugin({
5258

5359
Set a URL for source maps. Useful for hosting them on a host that requires authorization.
5460

55-
```javascript
61+
``` js
5662
new webpack.SourceMapDevToolPlugin({
5763
append: "\n//# sourceMappingURL=http://example.com/sourcemap/[url]",
58-
filename: '[name].map',
59-
}),
64+
filename: '[name].map'
65+
})
66+
```
67+
68+
And for cases when source maps are stored in the upper level directory:
69+
70+
``` js
71+
project
72+
|- dist
73+
|- public
74+
|- bundle-[hash].js
75+
|- sourcemaps
76+
|- bundle-[hash].js.map
77+
```
78+
79+
With next config:
80+
81+
``` js
82+
new webpack.SourceMapDevToolPlugin({
83+
filename: "sourcemaps/[file].map",
84+
publicPath: "https://example.com/project/",
85+
fileContext: "public"
86+
})
87+
```
88+
89+
Will produce the following URL:
90+
91+
``` js
92+
https://example.com/project/sourcemaps/bundle-[hash].js.map`
6093
```

0 commit comments

Comments
 (0)