Closed bbrk24 closed 1 month ago
esbuild intentionally keeps some comments because there're maybe other tools relying on them to work properly. For example vite supports /* vite-ignore */
, some coverage tools may read /* istanbul ignore */
etc. However, esbuild is not designed to keep all comments.
If you want to remove all comments, you can enable --minify-whitespace
.
Why would it keep that comment in particular though? What makes that comment different from the other comments in the file or the rest of the project?
Comments in expression position are sometimes preserved because some tools that use esbuild to transform code make use of them. These comments are intended for machines, not for humans, and were added due to specific requests (for example: https://github.com/evanw/esbuild/issues/2721). This behavior is deliberate, and is not a bug.
Comments in statement position aren't currently preserved unless they contain special pragmas. Legal comments are used by library authors to encourage users of their libraries to embed notices about copyright or similar things. This is described in the documentation here: https://esbuild.github.io/api/#legal-comments. This behavior is also deliberate, and is also not a bug.
Current reproducer (haven't tried to minimize it): https://github.com/bbrk24/template-qdeql/tree/2d25c18334d914c15b3932baac03db60c849d3ef
The output
index.mjs
includes one single-line comment:Either this is a bug because that comment is emitted when it shouldn't be, or because no other single-line comment is emitted and they all should.