Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mangle symbols change when otherwise-identical files are minified but one contains inline sourcemaps #543

Closed
stevenlybeck opened this issue Nov 17, 2020 · 1 comment

Comments

@stevenlybeck
Copy link

Really appreciating the simplicity (and docs!) of esbuild. I think we have an initial use case like many people - just replacing our minification step with esbuild.

It seems that esbuild uses a different set of characters for the mangling process when there is an inline sourcemap present on otherwise-identical JS files. From my perspective, it would be ideal if the resulting minified files were the same.

Running a very simple esbuild minify (cat test-with-sourcemap.js.txt | yarn esbuild --minify, cat test-without-sourcemap.js.txt | yarn esbuild --minify) on these two files, identical but for the presence of a sourcemap, results in different output:
test-with-sourcemap.js.txt
test-without-sourcemap.js.txt

I haven't looked at the esbuild code myself, but am tempted to give it a shot.

@evanw
Copy link
Owner

evanw commented Nov 17, 2020

This is because of the character frequency analysis that is used to derive the order of minified names for better gzip compression. The idea is to prefer using the most-used characters in the non-symbol parts of the document (keywords, strings, etc.) over characters that are less-used or absent. This is a very slight win, and is only approximate based on the input text instead of the output text because otherwise it would require minifying twice. Skipping over comments is easy to fix.

@evanw evanw closed this as completed in b0540e0 Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants