webpack-obfuscator
webpack-obfuscator copied to clipboard
Webpack obfuscator and Webpack banner plugin do not work together
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 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
*/