Registry / devops / rollup-plugin-obfuscator

rollup-plugin-obfuscator

JSON →
library1.1.0jsnpmunverified

rollup-plugin-obfuscator is a powerful Rollup plugin designed to integrate `javascript-obfuscator` into the build process. Unlike some alternatives, this plugin requires `javascript-obfuscator` to be installed as a separate peer dependency, ensuring users can always utilize the latest version of the obfuscator. The current stable version is 1.1.0, with updates typically aligning with new releases or needs of `javascript-obfuscator`. A key differentiator is its ability to perform obfuscation either on the entire bundle or, more efficiently, on individual files while excluding open-source dependencies, leading to significant performance improvements during the build process. It provides granular control over which files are obfuscated via include/exclude patterns and supports all configuration options available in `javascript-obfuscator` itself.

npm install rollup-plugin-obfuscator
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-OBFU
R
rollup-plugin-obfuscator
devopsjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

obfuscator
import obfuscator from 'rollup-plugin-obfuscator';
import { obfuscator } from 'rollup-plugin-obfuscator'; const obfuscator = require('rollup-plugin-obfuscator');
The plugin is exported as a default export. For CommonJS, `require('rollup-plugin-obfuscator').default` is correct but less common in modern Rollup configs.
RollupOptions
import type { RollupOptions } from 'rollup';
While not directly from this plugin, users often need Rollup types when configuring plugins in TypeScript.
ObfuscatorOptions
import type { ObfuscatorOptions } from 'javascript-obfuscator';
For precise typing of the `options` property, import types directly from `javascript-obfuscator`, as this plugin passes them through.

This quickstart demonstrates how to apply obfuscation to a Rollup bundle using the `rollup-plugin-obfuscator`. It shows the basic plugin setup and includes common `javascript-obfuscator` options for a strong obfuscation.

import obfuscator from 'rollup-plugin-obfuscator'; export default { input: 'src/main.js', output: { dir: 'dist', format: 'esm' }, plugins: [ obfuscator({ // Obfuscate the entire bundle (default is file-by-file) // global: true, options: { // Your javascript-obfuscator options here // See what's allowed: https://github.com/javascript-obfuscator/javascript-obfuscator compact: true, controlFlowFlattening: true, deadCodeInjection: true, identifierNamesGenerator: 'hexadecimal', selfDefending: true, sideEffects: true, splitStrings: true, stringArray: true, stringArrayThreshold: 0.75 } }), ] }
Debug
Known issues
gotchaThis plugin requires `javascript-obfuscator` to be installed separately as a peer dependency. Forgetting to install it will lead to runtime errors.
fix
Run `npm install --save-dev rollup-plugin-obfuscator javascript-obfuscator` or `yarn add --dev rollup-plugin-obfuscator javascript-obfuscator`.
affects: >=1.0.0
gotchaWhen `global` option is `false` (default), obfuscation is applied per-file. This means `include` and `exclude` options determine which individual files are processed. Ensure these patterns correctly target your source code and avoid external dependencies.
fix
Review your `include` and `exclude` arrays, especially if you observe unexpected obfuscation or non-obfuscation. The default `exclude: ['node_modules/**']` is usually sufficient, but might need adjustment for monorepos or specific build setups.
affects: >=1.0.0
gotchaOverly aggressive `javascript-obfuscator` settings can break your application, especially with complex frameworks or dynamic code evaluations. Test thoroughly after applying obfuscation.
fix
Start with milder obfuscation options and incrementally increase complexity. Rigorously test your application's functionality in a production-like environment after obfuscation. Consult the `javascript-obfuscator` documentation for details on each option.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'javascript-obfuscator'
The `javascript-obfuscator` package, a peer dependency, has not been installed.
fix
Install `javascript-obfuscator` alongside the plugin: `npm install --save-dev javascript-obfuscator`.
TypeError: Cannot read properties of undefined (reading 'transform')
Often indicates an issue where the plugin factory didn't return a valid plugin object or `javascript-obfuscator` wasn't correctly loaded.
fix
Ensure `javascript-obfuscator` is installed and the plugin configuration is syntactically correct, particularly the `options` object. Check your Rollup configuration for correct plugin array syntax.
Rollup 'transform' hook (plugin rollup-plugin-obfuscator) failed with error: Error: Options must be an object!
The `options` property passed to `rollup-plugin-obfuscator` is not a plain JavaScript object or is missing.
fix
Verify that the `options` property within the plugin configuration is a valid object, e.g., `obfuscator({ options: { /* ... */ } })`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
javascript-obfuscatorrequiredCore obfuscation library; required peer dependency.
rolluprequiredThe build tool this plugin extends; required peer dependency.
Agent activity
5 hits · last 30 days
node
5
Resources
rollup-plugin-obfuscator — npm install rollup-plugin-obfuscator · libregistry