z0ffy / vite-plugin-bundle-obfuscator

JavaScript obfuscator plugin for Vite, offering customizable options and multi-threading support to strengthen code security.
https://github.com/z0ffy/vite-plugin-bundle-obfuscator
MIT License
37 stars 0 forks source link
javascript-obfuscator obfuscated-code vite vite-javascript-obfuscator vite-plugin
vite-plugin-bundle-obfuscator logo # vite-plugin-bundle-obfuscator JavaScript `obfuscator` plugin for `Vite` environments [![awesome-vite](https://awesome.re/badge.svg)](https://github.com/vitejs/awesome-vite) [![][npm-release-shield]][npm-release-link] [![][npm-downloads-shield]][npm-release-link] [![][github-releasedate-shield]][github-releasedate-link] [![][github-license-shield]][github-license-link] [Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-pr-link]

English | 中文

![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

⭐️ Features

⚠️ Notice

📦 Installation

# Using npm
npm install vite-plugin-bundle-obfuscator -D

# Using pnpm
pnpm add vite-plugin-bundle-obfuscator -D

# Using yarn
yarn add vite-plugin-bundle-obfuscator -D

👨‍💻 Usage

  1. Install the plugin using your preferred package manager.
  2. Register the plugin in vite.config.js
  3. Customize the obfuscator configuration or use the default options.

Example:

import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';

const defaultObfuscatorConfig = {
  excludes: [],
  enable: true,
  log: true,
  autoExcludeNodeModules: false,
  threadPool: false,
  options: {
    compact: true,
    controlFlowFlattening: true,
    controlFlowFlatteningThreshold: 1,
    deadCodeInjection: false,
    debugProtection: false,
    debugProtectionInterval: 0,
    disableConsoleOutput: false,
    identifierNamesGenerator: 'hexadecimal',
    log: false,
    numbersToExpressions: false,
    renameGlobals: false,
    selfDefending: true,
    simplify: true,
    splitStrings: false,
    stringArray: false,
    stringArrayCallsTransform: false,
    stringArrayCallsTransformThreshold: 0.5,
    stringArrayEncoding: [],
    stringArrayIndexShift: true,
    stringArrayRotate: true,
    stringArrayShuffle: true,
    stringArrayWrappersCount: 1,
    stringArrayWrappersChainedCalls: true,
    stringArrayWrappersParametersMaxCount: 2,
    stringArrayWrappersType: 'variable',
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false,
  }
};

export default {
  plugins: [
    // vitePluginBundleObfuscator()
    vitePluginBundleObfuscator(defaultObfuscatorConfig)
  ]
};

🛠️ Options

Property Name Description Type Default Version
threadPool Configuration for the thread pool. boolean | ({ enable: true; size: number } | { enable: false }) false v1.2.0
apply Apply the plugin only for serve or build, or on certain conditions. 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean) build v1.1.0
autoExcludeNodeModules Enable auto exclude node_modules. boolean false v1.0.9
log Show or hide log output. boolean true v1.0.4
enable Enable or disable the obfuscator. boolean true v1.0.1
excludes Bundle names to be excluded. Starting from v1.0.8, RegExp is supported. (RegExp | string)[] [] v1.0.0
options Options for the JavaScript obfuscator. ObfuscatorOptions defaultObfuscatorConfig v1.0.0

📄 License

MIT License Copyright (c) 2024-present, Zoffy