esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Comments are not removed in build with Angular ESBuild

Open mirobo opened this issue 2 years ago • 1 comments

Hey there

I'm not sure if this is an issue in ESBuild or in Angular CLI, but the JS-bundles created end up still having comments like:

  /**
   * Check if the given MIME is a JSON MIME.
   * JSON MIME examples:
   *   application/json
   *   application/json; charset=UTF8
   *   APPLICATION/JSON
   *   application/vnd.company+json
   * @param mime - MIME (Multipurpose Internet Mail Extensions)
   * @return True if the given MIME is JSON, false otherwise.
   */

According to the docs and this comment, they should be removed by default?

   You are correct, esbuild does not preserve comments. It's not built to preserve comments. Preserving comments means it would operate more like a code formatter than a compiler. For example, you would probably want a token spanning tree instead of an AST. Doing this is currently a non-goal of esbuild. You should probably be using another tool for this.

Originally posted by @evanw in https://github.com/evanw/esbuild/issues/516#issuecomment-725093126

Also this comment doesn't contain @preserve , @license, //! or /*!.. so it should be a "normal" comment, that should be removed?

Versions: Node: 20.10.0 (Windows 10) ESbuild: 0.19.5 Angular: 17.0.8

mirobo avatar Jan 12 '24 08:01 mirobo

Since then, comment preservation was added for more kinds of comments. See also #2721 and v0.16.14. There is still no guarantee that esbuild will preserve all comments but it does now make an attempt to preserve comments in certain AST locations that are important for the major tools that use esbuild as a TypeScript transformation step.

evanw avatar Jan 12 '24 13:01 evanw

I'm closing this as it's working as intended, for the reasons described above.

evanw avatar Jan 23 '24 16:01 evanw