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

Anyhow to remove "comments" in minified js? #87

Closed
josteph opened this issue Dec 30, 2020 · 4 comments · Fixed by #166
Closed

Anyhow to remove "comments" in minified js? #87

josteph opened this issue Dec 30, 2020 · 4 comments · Fixed by #166

Comments

@josteph
Copy link

josteph commented Dec 30, 2020

Using ESBuildMinifyPlugin, is there anyway to remove the comments in the minified js file?

For example:
image

If using terser, we can add easily using comments: false in the output options.

@privatenumber
Copy link
Owner

This is by design on esbuild's end:

And all comments other than license-related comments are stripped out by esbuild anyway.

Can you open an issue here?

I think minification-benchmarks can also benefit from a more nuanced control over removing comments as other minifiers support it.

@josteph
Copy link
Author

josteph commented Jan 2, 2021

Thanks for the reference 👍

Edit:
I believe it has been answered here evanw/esbuild#578

@privatenumber
Copy link
Owner

I would still open a feature request about having granular control over whether license comments should be kept. Some authors might be referencing licenses in a separate file instead of the JS code.

Since esbuild preserves @license comments, you can try removing it to trick esbuild into thinking it's an ordinary comment.

As an example, you can use code-inject-loader to accomplish this:

{
	loader: 'code-inject-loader',
	options: {
		transform: src => src.replace(/@license/, '')
	}
},
{
	loader: 'esbuild-loader',
	...
}

Note that this is risky because it doesn't guarantee that @license is used as a part of a comment.

@privatenumber
Copy link
Owner

Re-opening as esbuild v0.11.15 has an option to remove comments.

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 a pull request may close this issue.

2 participants