terser icon indicating copy to clipboard operation
terser copied to clipboard

Minify multiple files with sourcemap inline

Open PascalSalesch opened this issue 5 years ago • 8 comments

Bug report or Feature request?

The following works with uglify-js (for JS but not ES) but not with terser:

const result = await minify(files, {
  sourceMap: {
    content: 'inline',
    includeSources: true,
    filename: `out.js`,
    url: `out.js.map`
  }
})

see proper file names on the right side

But with terser I get the following output:

Error: inline source map only works with singular input

Version (complete output of terser -V or specific git commit)

5.5.1

Complete CLI command or minify() options used

See here https://github.com/PascalSalesch/minify-error/blob/master/test.js#L6

  minify(files, {
    sourceMap: {
      content: 'inline',
      includeSources: true,
      filename: `out.js`,
      url: `out.js.map`
    }
  })

terser input

https://github.com/PascalSalesch/minify-error/blob/master/test.js#L6

terser output or error

> node -r esm test.js


/node_modules/terser/dist/bundle.min.js:26240
                    throw new Error("inline source map only works with singular input");
                          ^
Error: inline source map only works with singular input
    at minify (/node_modules/terser/dist/bundle.min.js:26240:27)
    at main (/test.js:7:24)
    at Object.<anonymous> (/test.js:18:1)
    at Generator.next (<anonymous>)

Expected result

To not throw

PascalSalesch avatar Jan 22 '21 00:01 PascalSalesch

Hey there!

This should totally be a thing. I also checked out your PR and it looks pretty good.

Source maps are always a tricky thing to change for me. Even after reading the docs in the readme a million times, I always forget how they're supposed to be configured.

It should totally be simplified, probably with an "auto" mode that defines sane defaults, but that's a topic for another time I guess.

fabiosantoscode avatar Mar 02 '21 22:03 fabiosantoscode

@fabiosantoscode @PascalSalesch what happened to this PR? From what I can tell it was never merged and this problem is still present in the latest version of terser.

johan-ohrn avatar Sep 19 '22 12:09 johan-ohrn

sourceMap: { content: 'inline' }

is not working for me

olfek avatar Feb 23 '23 14:02 olfek

okay babel minify worked for me

minify(
    fs.readFileSync(path + ".js", "utf8"),
    undefined,
    { sourceType: 'module', inputSourceMap: true, sourceMaps: 'inline' }
)

olfek avatar Feb 23 '23 14:02 olfek

this is still happening for me, any workaround for this issue?

kotasudhakar avatar Jul 17 '23 12:07 kotasudhakar

@fabiosantoscode @PascalSalesch what happened to this PR? From what I can tell it was never merged and this problem is still present in the latest version of terser.

Unfortunately I never got around to write tests for it and I didn't want to open a PR where I comment out tests. Feel free to open a PR with the changes from https://github.com/PascalSalesch/terser/pull/1/files

I'm not sure when I'll have time to polish it

PascalSalesch avatar Jul 17 '23 12:07 PascalSalesch

Looks like it's easier than I thought! Testing would help but also some feedback on real world use. Source maps are tricky to get right

fabiosantoscode avatar Jul 17 '23 17:07 fabiosantoscode