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

feat: support to preserve specific comments #2632

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unbyte
Copy link

@unbyte unbyte commented Oct 26, 2022

According to #1439 and #221 (comment), it seems that esbuild is not tend to supoort to preserve comments, but in our internal project we need to keep certain special placeholder comments for some tools to inject code, so I simply implement the basic feature we need and open this PR only to help others with the same needs get this patch easily.

To apply this patch:

$ curl -L https://github.com/evanw/esbuild/pull/2632.patch | git am

Example

CLI

$ esbuild --outfile=output.js --preserve-comments=\[PositionFor input.js

Input

/* [PositionForAppBegin] */
App({})
/* [PositionForAppEnd] */
/* should be removed */

Output

/* [PositionForAppBegin] */
App({});
/* [PositionForAppEnd] */

@benmccann
Copy link

Could this also be used to preserve all comments by passing something like .*? Storybook has a need to preserve comments as they're used for automatically generating documentation within Storybook. In the Svelte plugin, we need to first run any TypeScript through a compiler to convert to JavaScript so that the Svelte compiler can understand it. The fact that esbuild is removing comments is causing us major headaches (storybookjs/storybook#24096)

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

Successfully merging this pull request may close these issues.

None yet

2 participants