web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.75k stars 562 forks source link

[SwcJsMinimizerRspackPlugin] Alignment with terser-webpack-plugin for format.comments #7486

Open andrewcartwright1 opened 3 months ago

andrewcartwright1 commented 3 months ago

What subject does this issue tracking?

The current implementation of the SwcJsMinimizerRspackPlugin format.comments (https://rspack.dev/plugins/rspack/swc-js-minimizer-rspack-plugin) 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 when using SwcJsMinimizerRspackPlugin as a minimizer

JSerFeng commented 3 months ago

This feature can be sent to swc repository as well