jfortunato / esbuild-plugin-manifest

Esbuild plugin for building an asset manifest file.
MIT License
31 stars 5 forks source link

Fix sourcemap chunk naming conflict #26

Closed emilbjorklund closed 2 months ago

emilbjorklund commented 2 months ago

Problem

Naming conflicts in the manifest for output chunks are handled by checking if the name-part of the output file name is chunk. For sourcemaps, the double extension (.js.map) will mean that chunk names will be e.g. chunk.js and the comparison fails, causing duplicate keys.

Fixes the continued issues mentioned in the comments on #22 after it was closed.

Solution

Parse the name twice (!!), which will leave normal names untouched, but remove "double extension" names like .js.map or .min.css. It's a bit of a weird solution, but felt like the most efficient approach if wanting to avoid having to hard-code extension and create a more general solution.

Note: Chunk hashes change in the test, which I assume is on account of the sourcemapping-URL being present in the file contents. I haven't verified this though.

jfortunato commented 2 months ago

Excellent, thank you!