Skip to content

Commit

Permalink
feat: respect devtool values for source map generation (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 5, 2019
1 parent 080baff commit dd37ca1
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,16 @@ module.exports = {
Type: `Boolean`
Default: `false`

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

Why?

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

The plugin respect the [`devtool`](https://webpack.js.org/configuration/devtool/).
Using supported `devtool` values enable source map generation.

Use source maps to map error message locations to modules (this slows down the compilation).
If you use your own `minify` function please read the `minify` section for handling source maps correctly.

Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TerserPlugin {
chunkFilter = () => true,
warningsFilter = () => true,
extractComments = true,
sourceMap = false,
sourceMap,
cache = true,
cacheKeys = (defaultCacheKeys) => defaultCacheKeys,
parallel = true,
Expand Down Expand Up @@ -155,6 +155,14 @@ class TerserPlugin {
}

apply(compiler) {
this.options.sourceMap =
typeof this.options.sourceMap === 'undefined'
? compiler.options.devtool &&
/^((inline|hidden|nosources)-)?source-?map/.test(
compiler.options.devtool
)
: Boolean(this.options.sourceMap);

const buildModuleFn = (moduleArg) => {
// to get detailed location info about errors
// eslint-disable-next-line no-param-reassign
Expand Down
Loading

0 comments on commit dd37ca1

Please sign in to comment.