rollup-plugin-post-obfuscator

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

Rollup plugin that obfuscates JavaScript output after the bundle is generated. Current stable version is 1.0.0. It leverages javascript-obfuscator under the hood and supports dynamic import obfuscation, inclusion/exclusion patterns, and source map handling. Unlike other obfuscation plugins that operate during the build process, this plugin post-processes the output, making it compatible with various output formats and easier to integrate. It ships TypeScript types and requires Node >=16 and Rollup <5.

error Error: Cannot find module 'rollup-plugin-post-obfuscator'
cause Missing npm install or using wrong package name.
fix
Run 'npm install --save-dev rollup-plugin-post-obfuscator'
error TypeError: obfuscator is not a function
cause Named import instead of default import.
fix
Use 'import obfuscator from ...' not '{ obfuscator }'.
error ERR_PEER_DEP_INVALID: rollup@5.0.0 invalid for rollup-plugin-post-obfuscator@1.0.0
cause Plugin requires Rollup <5, but Rollup 5 is installed.
fix
Downgrade Rollup to 4.x.
gotcha Plugin requires Rollup <5; using with Rollup 5 will cause a peer dependency warning and may break.
fix Use Rollup 4 or earlier.
gotcha The 'outDir' option must match Rollup's output.dir exactly; otherwise, the plugin may fail to find generated files.
fix Set obfuscator({ outDir: output.dir }) or ensure consistency.
gotcha Obfuscation of source maps is not well documented; if source maps are enabled, the plugin may not update them correctly.
fix Test with source maps or disable them if obfuscation breaks them.
gotcha Dynamic import obfuscation may not work reliably with all output formats (e.g., SystemJS).
fix Test with your specific format; consider using 'es' or 'cjs'.
npm install rollup-plugin-post-obfuscator
yarn add rollup-plugin-post-obfuscator
pnpm add rollup-plugin-post-obfuscator

Basic Rollup config using the obfuscator plugin with typical options including include/exclude patterns and custom javascript-obfuscator options.

// rollup.config.js
import obfuscator from 'rollup-plugin-post-obfuscator';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'es',
  },
  plugins: [
    obfuscator({
      outDir: 'dist',
      include: ['**/*.js'],
      exclude: ['vendor/**'],
      JavaScriptObfuscatorOptions: {
        compact: true,
        controlFlowFlattening: true,
      },
    }),
  ],
};