grunt-terser icon indicating copy to clipboard operation
grunt-terser copied to clipboard

Per-file SourceMappingUrl

Open ProudOne opened this issue 4 years ago • 2 comments

Setting options.sourceMap.url will now prepend the url to every minfied files' sourceMappingURL rather than overriding it.

With an output file named dist/library.js and these options:

    options: {
      compress: {
         ...
      },
      sourceMap: { url : '' },
    }

This generates the map file as before, but now adds //# sourceMappingURL=libraries.js.map to the end of dist/library.js. With the url set to https://example.org, we get //# sourceMappingURL=https://example.org/libraries.js.map.

ProudOne avatar Nov 04 '21 08:11 ProudOne

Hello, can you add more examples where it's not working as expected?

adascal avatar Nov 04 '21 10:11 adascal

Sure.

Given an url like https://example.org, grunt-terser will call terser with the url set to this exactly, meaning even though we're creating a file called library.js, the sourceMappingUrl will end up as //# sourceMappingURL=https://example.org. Browsers will then try to find the map for library.js at https://example.org and come up empty because it's missing the reference to the actual file.

This PR fixes that, adding code that adds the file name to the url, so the browser can find the map on the server.

ProudOne avatar Nov 05 '21 14:11 ProudOne