vite-plugin-bundle-obfuscator

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

A JavaScript obfuscation plugin for Vite environments, version 1.11.0, with a release cadence of roughly monthly updates. Supports Vite 4/5/6/7/8 (including Rolldown), Nuxt.js, and library mode. Key differentiators: multi-threaded obfuscation, automatic node_modules exclusion, support for worker files, and a built-in code size analyzer. Ships TypeScript types. Requires Node >=20.

error Module "vite-plugin-bundle-obfuscator" has been resolved to ESM but a CommonJS module is required.
cause The package is ESM-only and cannot be required with require().
fix
Use import instead: import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator'
error TypeError: vitePluginBundleObfuscator is not a function
cause Using named import instead of default import.
fix
Use: import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator' (not in curly braces)
error Error: The plugin requires Vite 4.0.0 or newer, but found version 3.x.
cause Vite version is too old; minimum required is 4.0.0.
fix
Update Vite to version 4.0.0 or newer: npm install vite@latest
error FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
cause Build process ran out of memory due to large codebase being obfuscated.
fix
Set NODE_OPTIONS=--max-old-space-size=8192 before build command.
breaking Node.js 18 is no longer supported as of v1.11.0. Minimum required version is 20.
fix Upgrade Node.js to version 20 or later.
gotcha If you experience out-of-memory errors during build, increase memory limit using NODE_OPTIONS with --max-old-space-size.
fix Set NODE_OPTIONS=--max-old-space-size=8192 before the build command.
gotcha When configuring node_modules chunk splitting, prefix the exact package name to avoid overlapping matches (e.g., 'vue' matches both 'vue' and 'vue-router').
fix Use more specific names like 'vue-router' before 'vue' in the chunk splitting array.
deprecated Option 'stringArrayEncoding' with value 'rc4' is deprecated and will be removed in future versions. Use 'base64' instead.
fix Replace 'rc4' with 'base64' in the obfuscator options.
npm install vite-plugin-bundle-obfuscator
yarn add vite-plugin-bundle-obfuscator
pnpm add vite-plugin-bundle-obfuscator

Basic setup of vite-plugin-bundle-obfuscator in vite.config.ts with common obfuscator options.

import { defineConfig } from 'vite';
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';

export default defineConfig({
  plugins: [
    vitePluginBundleObfuscator({
      enable: true,
      log: true,
      autoExcludeNodeModules: true,
      excludes: [],
      options: {
        compact: true,
        controlFlowFlattening: true,
        controlFlowFlatteningThreshold: 0.75,
        deadCodeInjection: false,
        debugProtection: false,
        disableConsoleOutput: true,
        identifierNamesGenerator: 'hexadecimal',
        numbersToExpressions: true,
        simplify: true,
        stringArray: true,
        stringArrayEncoding: ['base64'],
        stringArrayThreshold: 0.75,
        transformObjectKeys: true,
        unicodeEscapeSequence: false
      }
    })
  ]
});