Per-file SourceMappingUrl
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.
Hello, can you add more examples where it's not working as expected?
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.