Vite JavaScript Obfuscator Plugin

3.1.0 · active · verified Sun Apr 19

vite-plugin-javascript-obfuscator is a Vite plugin designed to integrate the `javascript-obfuscator` library into Vite projects, enabling code obfuscation during the build or serve process. The current stable version is 3.1.0. This plugin allows developers to apply various obfuscation techniques to their JavaScript, JSX, TypeScript, and TSX files, helping to protect source code from reverse engineering and tampering. It provides a configurable interface to pass options directly to `javascript-obfuscator`, including `debugProtection`, `controlFlowFlattening`, and many others, allowing fine-grained control over the obfuscation intensity and effects. Its key differentiator is seamless integration within the Vite ecosystem, leveraging Vite's HMR for development and optimized builds for production, making it easy to add a layer of code protection without complex build-tool configurations. There is no publicly stated strict release cadence, but updates align with `javascript-obfuscator` and Vite ecosystem changes.

Common errors

Warnings

Install

Imports

Quickstart

This configuration demonstrates how to integrate `vite-plugin-javascript-obfuscator` into a Vite project, applying comprehensive obfuscation settings to JavaScript/TypeScript files during the build process for enhanced code protection.

import { defineConfig } from 'vite';
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator';

export default defineConfig({
  plugins: [
    obfuscatorPlugin({
      // Apply obfuscation only during the build process
      apply: 'build',
      // Configure files to include (e.g., specific paths or regex)
      include: ['src/**/*.js', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.tsx'],
      // Basic javascript-obfuscator options for robust protection
      options: {
        compact: true,
        controlFlowFlattening: true,
        controlFlowFlatteningThreshold: 1,
        debugProtection: true,
        debugProtectionInterval: true,
        disableConsoleOutput: true,
        identifierNamesGenerator: 'hexadecimal',
        log: false,
        numbersToExpressions: true,
        simplify: true,
        splitStrings: true,
        stringArray: true,
        stringArrayCallsTransform: true,
        stringArrayCallsTransformThreshold: 1,
        stringArrayEncoding: ['base64'],
        stringArrayIndexShift: true,
        stringArrayRotate: true,
        stringArrayShuffle: true,
        stringArrayWrappersCount: 5,
        stringArrayWrappersType: 'function',
        stringArrayThreshold: 1,
        transformObjectKeys: true,
        unicodeEscapeSequence: true
      }
    })
  ]
});

view raw JSON →