Skip to content

Commit dd37ca1

Browse files
authoredSep 5, 2019
feat: respect devtool values for source map generation (#140)
1 parent 080baff commit dd37ca1

File tree

4 files changed

+377
-2
lines changed

4 files changed

+377
-2
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,16 @@ module.exports = {
284284
Type: `Boolean`
285285
Default: `false`
286286

287-
**Only works with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
287+
**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
288288

289289
Why?
290290

291291
- `eval` wraps modules in `eval("string")` and the minimizer does not handle strings.
292292
- `cheap` has not column information and minimizer generate only a single line, which leave only a single mapping.
293293

294+
The plugin respect the [`devtool`](https://webpack.js.org/configuration/devtool/).
295+
Using supported `devtool` values enable source map generation.
296+
294297
Use source maps to map error message locations to modules (this slows down the compilation).
295298
If you use your own `minify` function please read the `minify` section for handling source maps correctly.
296299

‎src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TerserPlugin {
2828
chunkFilter = () => true,
2929
warningsFilter = () => true,
3030
extractComments = true,
31-
sourceMap = false,
31+
sourceMap,
3232
cache = true,
3333
cacheKeys = (defaultCacheKeys) => defaultCacheKeys,
3434
parallel = true,
@@ -155,6 +155,14 @@ class TerserPlugin {
155155
}
156156

157157
apply(compiler) {
158+
this.options.sourceMap =
159+
typeof this.options.sourceMap === 'undefined'
160+
? compiler.options.devtool &&
161+
/^((inline|hidden|nosources)-)?source-?map/.test(
162+
compiler.options.devtool
163+
)
164+
: Boolean(this.options.sourceMap);
165+
158166
const buildModuleFn = (moduleArg) => {
159167
// to get detailed location info about errors
160168
// eslint-disable-next-line no-param-reassign

0 commit comments

Comments
 (0)
Failed to load comments.