esbuild-loader icon indicating copy to clipboard operation
esbuild-loader copied to clipboard

Support `legalComments: "linked"`

Open ybiquitous opened this issue 3 years ago • 1 comments

Feature request

Hi authors, thank you for creating this excellent tool! I can receive significant performance benefits for building speed. 😄

I wish wonderful if esbuild-loader could support legalComments: "linked" because it could further reduce the size of comments. Also, linking comments is the default behavior of Webpack.

Unfortunately, legalComments: "linked" causes build errors. 😢

Cannot transform with linked or external legal comments

Why?

By default, Webpack supports minification with linked license files. So, I think it's useful for many people that esbuild-loader can follow the behavior.

For details, see my reproduction repository: https://github.com/ybiquitous/esbuild-loader-legal-comments

Here are the build outputs on the repo. The default.* files below are by the Webpack default configuration:

$ ls dist/
default.js             eof.js
default.js.LICENSE.txt linked.js

$ head -1 dist/default.js
/*! For license information please see default.js.LICENSE.txt */

$ head -2 dist/default.js.LICENSE.txt
/*!
  Copyright (c) 2018 Jed Watson.

I'm unfamiliar with esbuild and don't know the error details, but I will help if there is anything I can.

Feel free to close the issue if there would be some difficulties. Thanks.

Alternatives

No response

Additional context

No response

ybiquitous avatar Jul 08 '22 04:07 ybiquitous

esbuild doesn't support linked in the Transform API, but I think we can work around this by changing it to eof and extracting the comments out with magic-string and emitting it as an asset.

PR welcome!

privatenumber avatar Jul 08 '22 06:07 privatenumber

FYI esbuild has added support for extracting legal comments in the Transform API in https://github.com/evanw/esbuild/releases/tag/v0.16.10

privatenumber avatar Dec 20 '22 02:12 privatenumber

Thank you! 🎉

ybiquitous avatar Jan 12 '23 23:01 ybiquitous