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

Minified line lengths #3170

Closed
jawj opened this issue Jun 16, 2023 · 3 comments
Closed

Minified line lengths #3170

jawj opened this issue Jun 16, 2023 · 3 comments

Comments

@jawj
Copy link

jawj commented Jun 16, 2023

I bundle a library using esbuild with --minify. Most of the minified code is in lines of >30,000 characters.

When the library throws an Error, the stack trace includes a code excerpt, which I think must be defined as a specific number of lines. This means that users have to scroll back up a very long way to find the error message.

I'd like to keep minifying the library, but it would be great if there was an option to emit shorter lines. Two possibilities that come to mind:

  • Always emit \n instead of ; when the effect is the same (keeps output size constant)
  • Emit a \n after a ; if there hasn't been one for the last N characters (potentially simpler to implement)

Is either of these (or something else) a possibility?

@evanw
Copy link
Owner

evanw commented Jun 16, 2023

I’m looking at what other tools do. Terser and UglifyJS seem to have a max_line_len setting. Google Closure Compiler says it adds like breaks approximately every 500 characters as a holdover from a time when buggy routers corrupted JavaScript files with long lines.

It would be nice to not have the size be any bigger, in which case this could happen automatically. Computing whether it’s safe to omit a semicolon is somewhat complicated both because the printer doesn’t necessarily know what will be printed next, and because going back and changing a semicolon to a newline messes up source map generation.

Note to self: I’ll try to think of a way of doing this. Maybe printSemicolonIfNeeded can set a flag and later code can rewrite the semicolon into a newline. It shouldn’t be too complicated regarding source maps if it’s at the end of the current code string.

@jawj
Copy link
Author

jawj commented Jun 16, 2023

Many thanks for the quick reply @evanw (and many thanks for esbuild too, of course)! I look forward to seeing what you come up with.

@evanw
Copy link
Owner

evanw commented Jun 21, 2023

I looked into this a bit. Relying on ASI is possible but hurts gzip size, so it's probably not something that would be turned on by default.

@evanw evanw closed this as completed in 7d5df10 Jun 21, 2023
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