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

Regex support for format.comments of minifier #9674

Open
DynamiteAndy opened this issue Oct 23, 2024 · 4 comments
Open

Regex support for format.comments of minifier #9674

DynamiteAndy opened this issue Oct 23, 2024 · 4 comments
Assignees
Milestone

Comments

@DynamiteAndy
Copy link

Describe the feature

The current implementation of the minimizers format.comments does not allow regex to be used like https://webpack.js.org/plugins/terser-webpack-plugin/#preserve-comments

new TerserPlugin({
        terserOptions: {
          format: {
            comments: /@.* [\w|\d].*|==\/?UserScript==/i
          }
        }
      })

it instead requires either comments?: false | 'some' | 'all';, would like to propose supporting a regex so that certain comments will be left untouched

Babel plugin or link to the feature description

https://webpack.js.org/plugins/terser-webpack-plugin/#preserve-comments

Additional context

I raised this originally in the rspack repo but was told it can be sent here as well.

@kdy1 kdy1 added this to the Planned milestone Oct 24, 2024
@lukpsaxo
Copy link

I've been tracking down why our bundle size increased by 10kb and the issue is we have a babel plugin that adds pure comments and then because of this: #9255

all of those comments now stay in the minified file.

I would love at least to be able to configure annotations to not be kept.

@kdy1
Copy link
Member

kdy1 commented Nov 18, 2024

@lukpsaxo It's supported. https://swc.rs/docs/configuration/minification#jscminifyformat
The unsupported thing is regex or function

@kdy1 kdy1 changed the title Alignment with terser-webpack-plugin for format.comments Regex support for format.comments Nov 18, 2024
@kdy1 kdy1 changed the title Regex support for format.comments Regex support for format.comments of minifier Nov 18, 2024
@lukpsaxo
Copy link

lukpsaxo commented Nov 18, 2024

@kdy1 I want to keep license comments and not keep pure annotations... I think that is not covered - at least the docs say only "some" and the code-change introducing the keeping of pure annotations didn't look like it was behind its own option (https://github.com/swc-project/swc/pull/9449/files#diff-1955969d1960346434767b5a39f0310edcab0f857933079e6048a50e67b65e38)

@kdy1 kdy1 self-assigned this Nov 19, 2024
@abettadapur
Copy link

abettadapur commented Nov 19, 2024

+1 to this
We have a very large project, and are blocked on upgrading SWC past 1.7.12 because the PURE comments adds multiple hundreds of KBs to our bundles

I don't need full regex support, but it would be great to preserve license comments and strip the PURE comments in the minifier, as they provide no value at runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants
@abettadapur @kdy1 @lukpsaxo @DynamiteAndy and others