webpack-obfuscator is a JavaScript Obfuscator plugin and loader designed specifically for Webpack 5 and above. It integrates the robust `javascript-obfuscator` library into the Webpack build process, allowing developers to protect their JavaScript code by making it harder to read and reverse-engineer. The current stable version is 3.6.1. Releases appear to be frequent, focusing on dependency updates and minor enhancements, indicating an active maintenance schedule. A key differentiator is its seamless integration as both a Webpack plugin and a loader, offering flexibility in how obfuscation is applied, including the ability to exclude specific bundles or files. It also supports the obfuscator.io Pro API for advanced, cloud-based obfuscation techniques, requiring `javascript-obfuscator` version 5.0.0 or higher for this feature.
npm install webpack-obfuscatorVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic Webpack configuration applying `webpack-obfuscator` as both a plugin (for global bundle obfuscation with exclusions) and a loader (for individual file obfuscation before other loaders, using `enforce: 'post'`).
Upgrade to Webpack 5 or higher, or downgrade `webpack-obfuscator` to a 2.x release if tied to Webpack 4.
Ensure `javascript-obfuscator` is installed: `npm install --save-dev javascript-obfuscator`.
Verify `javascript-obfuscator` version in `package.json` and update if necessary (`npm install javascript-obfuscator@latest`).
Add `enforce: 'post'` to the loader rule in your webpack configuration: `{ test: /\.js$/, enforce: 'post', use: { loader: WebpackObfuscator.loader, ... } }`.For the plugin, ensure `excludes` array matches your compiled bundle names (e.g., `['my-bundle.js']`). For the loader, use `path.resolve(__dirname, 'src/excluded-file.js')`.
For CommonJS, `const WebpackObfuscator = require('webpack-obfuscator');` is shown in the README. For ESM, use `import WebpackObfuscator from 'webpack-obfuscator';`Install the peer dependency: `npm install --save-dev javascript-obfuscator`.
When using `WebpackObfuscator.loader`, options should be nested under `options` in the `use` object: `{ use: { loader: WebpackObfuscator.loader, options: { rotateStringArray: true } } }`.Downgrade `webpack-obfuscator` to a 2.x version (e.g., `npm install webpack-obfuscator@^2.0.0 --save-dev`) or upgrade your project to Webpack 5.