webpack-obfuscator icon indicating copy to clipboard operation
webpack-obfuscator copied to clipboard

Webpack obfuscator and Webpack banner plugin do not work together

Open hrant-nurijanyan opened this issue 3 years ago • 1 comments

I am trying to obfuscate my javascript code and after adding webpack-obfuscator as a plugin, webpack.BannerPlugin stopped working. I've read that I need to add @license or @preserve to the license, but it does not help, can anyone help me?

hrant-nurijanyan avatar Feb 08 '22 12:02 hrant-nurijanyan

@hrant-nurijanyan hello from the future. I wanted to do the same and also found it impossible. @preserve worked for me, but then Terser is like "Oh you want to preserve these in a separate file, cool". No Terser I do not. I want to preserve them in place. There might be some special combo using extractComments and format.comments (as mentioned in extractComments docs) but I couldn't figure it out. In the end I used the object option and removed the filename and condition params to fall back to default, and then put the banner in the banner option. I used @preserve for Obfuscator.

webpack.BannerPlugin not needed.

Example

  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        extractComments: {
          banner: (licenseFile) => {
            return `\n @preserve \n LinkSDK web v${new_version} \n License information can be found in ${licenseFile}\n`;
          }
        }
      })
    ]
  },

Outputs

/*! 
 @preserve 
 LinkSDK web v2.0.0 
 License information can be found in Lean.min.js.LICENSE.txt
 */

seb-lean avatar Mar 19 '24 17:03 seb-lean