Rollup Obfuscator

raw JSON →
4.1.1 verified Mon Apr 27 auth: no javascript

A Rollup and Vite plugin for obfuscating JavaScript bundles using javascript-obfuscator. Current stable version is 4.1.1, released in September 2024. It supports Rollup v2, v3, and v4, and Vite build-time only. Key differentiators: it works as an end-of-pipeline plugin, filters files by pattern, and sets sensible defaults (sourceMap: true, stringArray: false) to reduce breakage. Requires Node 16+ and javascript-obfuscator v4 as a peer dependency. The plugin is actively maintained with regular releases addressing bugs and compatibility.

error Error: Cannot find module 'javascript-obfuscator'
cause Missing peer dependency javascript-obfuscator
fix
npm install javascript-obfuscator --save-dev
error TypeError: obfuscator is not a function
cause Using default import instead of named import (v3+).
fix
Change to: import { obfuscator } from 'rollup-obfuscator';
error Error: Rollup plugin 'rollup-obfuscator' must be at the end of the plugins array
cause Plugin placed before other plugins that generate output.
fix
Move the obfuscator() call to the last position in the plugins array.
breaking v4 removed options.global. The option no longer exists.
fix Remove options.global from your plugin call. The default behavior now matches v3's global: false.
breaking v4 requires Node 16+. Older Node versions are not supported.
fix Upgrade Node to v16 or later.
breaking v4 changed default obfuscator options: sourceMap now defaults to true, stringArray defaults to false.
fix If you rely on the old defaults, explicitly set sourceMap: false and stringArray: true in options.
gotcha Plugin must be placed at the end of the plugins array to ensure other transforms run before obfuscation.
fix Always list obfuscator() as the last plugin.
gotcha javascript-obfuscator is a peer dependency; you must install it separately or the plugin will fail.
fix Run 'npm install javascript-obfuscator --save-dev'.
deprecated In v2, the library used a default export; v3+ switched to named export 'obfuscator'.
fix Use import { obfuscator } from 'rollup-obfuscator' instead of import obfuscator from 'rollup-obfuscator'.
npm install rollup-obfuscator
yarn add rollup-obfuscator
pnpm add rollup-obfuscator

Basic Rollup configuration with obfuscator plugin at the end of plugins array, demonstrating import and usage.

// rollup.config.js
import { obfuscator } from 'rollup-obfuscator';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    // other plugins...
    obfuscator({
      // javascript-obfuscator options (optional)
      compact: true,
      controlFlowFlattening: false,
      // plugin-specific options
      include: ['**/*.js'],
      exclude: ['node_modules/**']
    })
  ]
};