'Babel remove comment blocks in js files

This is my babel.config.js:

module.exports = {
  presets: ["@vue/cli-plugin-babel/preset"],
  plugins: [
    [
      "search-and-replace",
      {
        rules: [
          {
            search: /(?:\/\*(?:[^\*]|\**[^\*\/])*\*+\/)|(?:\/\/[\S ]*)/,
            replace: "",
          },
        ],
      },
    ],
  ],
};

I used babel-plugin-search-and-replace to replace characters.

My goal is to remove comments from js files, for example: enter image description here I don't want the user could see the package description in the source codes. I tried other plugins and didn't succeed.

Thanks for your helping.



Solution 1:[1]

Solved by webpack:

  chainWebpack: (config) => {
    config.optimization.minimizer("terser").tap((args) => {
      args[0].terserOptions.output = {
        ...args[0].terserOptions.output,
        comments: false, // exclude all comments from output
      };
      return args;
    });
  },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ShaSha