Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-plugin-bundle-obfuscator

z0ffy20.6kMIT1.8.0TypeScript support: included

JavaScript obfuscator plugin for Vite environments

vite, vite-rolldown, nuxt, obfuscator, vite-plugin-obfuscator, vite-bundle-obfuscator, vite-javascript-obfuscator, javascript, javascript-obfuscator

readme

vite-plugin-bundle-obfuscator logo

vite-plugin-bundle-obfuscator

适用于Vite环境的JavaScript混淆器插件

awesome-vite

Changelog · Report Bug · Request Feature

English | 中文

⭐️ 特性

  • ✅ ⚡ 支持Vite项目中的JavaScript混淆。
  • ✅ 🚀 多线程支持,以获得更好的性能。
  • ✅ ⚙️ 可定制的混淆器选项,以满足您的需求。
  • ✅ 🛡️ 自动排除node_modules
  • ✅ 📦 支持node_modules拆分块。

⚠️ 注意

  • 如果遇到内存溢出,修改打包命令为"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build", max-old-space-size的值根据配置自行设置。
  • 在设置node_modules分包时,请把准确的包名前置。例如:["vue-router", "vue"],"vue"可以同时匹配到vue以及vue-router

🌐 在线试用

Vite - VanillaVite - VueVite - ReactVite - PReactVite - litVite - SvelteVite - SolidVite - Qwik ✦ ...

📦 安装

# 使用npm
npm install vite-plugin-bundle-obfuscator -D

# 使用pnpm
pnpm add vite-plugin-bundle-obfuscator -D

# 使用yarn
yarn add vite-plugin-bundle-obfuscator -D

👨‍💻 使用

  1. 使用您首选的软件包管理器安装插件。
  2. vite.config.js中注册插件。
  3. 自定义混淆器配置或使用默认选项。

示例:

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

// 全部配置
const allObfuscatorConfig = {
  excludes: [],
  enable: true,
  log: true,
  autoExcludeNodeModules: false,
  // autoExcludeNodeModules: { enable: true, manualChunks: ['vue'] }
  threadPool: false,
  // threadPool: { enable: true, size: 4 }
  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,
    ignoreImports: true,
    stringArray: true,
    stringArrayCallsTransform: true,
    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(defaultObfuscatorConfig)
  ]
};

// 简化配置
const minimizeObfuscatorConfig = {
  autoExcludeNodeModules: true,
  // autoExcludeNodeModules: { enable: true, manualChunks: ['vue'] }
  threadPool: true,
  // threadPool: { enable: true, size: 4 }
};

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

// 默认配置
export default {
  plugins: [
    vitePluginBundleObfuscator()
  ]
};

🚀 性能比较

拥有 7000+ modules400+ bundles4C 8G 机器上:

  • ThreadPool Enabled : 🟩🟩🟩⬜⬜⬜⬜⬜⬜ (大约30秒)
  • ThreadPool Disabled : 🟥🟥🟥🟥🟥🟥🟥🟥🟥 (大约90秒)

🛠️ 选项

属性 描述 类型 默认值 版本
threadPool 线程池的配置。 boolean | ({ enable: true; size: number } | { enable: false }) false v1.2.0
apply 仅将插件应用于服务或构建,或在特定条件下。 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean) build v1.1.0
autoExcludeNodeModules 启用自动排除node_modules。 boolean | ({ enable: true; manualChunks: string[] } | { enable: false }) false v1.0.9(原本为boolean,在v1.3.0版本中扩展到当前类型)
log 显示或隐藏日志输出。 boolean true v1.0.4
enable 启用或禁用混淆器。 boolean true v1.0.1
excludes 排除的bundle名。从v1.0.8开始,支持正则。 (RegExp | string)[] [] v1.0.0
options JavaScript混淆器的选项。 ObfuscatorOptions defaultObfuscatorConfig v1.0.0

📄 License

MIT License Copyright (c) 2024-present, Zoffy

changelog

Changelog

Unreleased -

v1.8.0 - 10 July 2025

  • feat: bump version to 1.8.0 and add nuxt keyword
  • fix(config): move dts configuration to baseConfig for better maintainability
  • feat: optimize
  • feat: add support for Nuxt.js
  • chore: update CHANGELOG.md

Fixes

  • fix: handle source map parsing in obfuscateBundle function @z0ffy

Refactoring and Updates

  • refactor(deps): replace lodash-es with native JSON methods @z0ffy

General Changes

  • build(config): move dts generation to cjs format only @z0ffy

v1.7.0 - 27 June 2025

  • chore: update version to 1.7.0 in package.json
  • chore: update package.json, upgrade Vite version to 7.0.0
  • chore: add lodash-es and @types/lodash-es dependencies, and use cloneDeep function in utils
  • chore: refactor commitlint configuration and add an ESLint configuration file
  • chore: update CHANGELOG for v1.6.0 release and add new features section

Chores And Housekeeping

  • chore: update package.json, upgrade Vite version to 7.0.0, add support for Vite 5 and above, refactor transformIndexHtml handling logic @z0ffy

v1.6.0 - 19 June 2025

  • chore: update version to 1.6.0 in package.json
  • feat: enhance obfuscation process with registry management
  • chore(deps-dev): update dependencies to latest versions
  • chore(deps-dev): bump eslint from 9.24.0 to 9.29.0
  • chore(deps-dev): bump @eslint/js from 9.24.0 to 9.29.0
  • chore(deps-dev): bump @types/node from 22.14.1 to 24.0.2
  • feat: add obfuscation support for library bundles and enhance render …
  • chore: update CHANGELOG for v1.5.0 release

New Features

  • feat: add obfuscation support for library bundles and enhance render chunk handling @z0ffy

v1.5.0 - 17 April 2025

  • chore: update version to 1.5.0 in package.json
  • feature/add stringArray
  • chore(deps): update dependencies to latest versions

New Features

  • feat: enhance feature checks and improve type handling in utility functions @z0ffy
  • feat: add support for stringArray option @z0ffy

v1.4.2 - 3 March 2025

  • chore: update dependencies and version to 1.4.2; update CHANGELOG.md
  • build(deps): update dependencies and configure pnpm
  • chore(deps-dev): bump @stylistic/eslint-plugin from 2.13.0 to 4.2.0
  • chore(deps-dev): bump eslint from 9.18.0 to 9.21.0
  • chore(deps-dev): bump tsup from 8.3.5 to 8.4.0
  • chore(deps-dev): bump @eslint/js from 9.18.0 to 9.21.0
  • chore(deps-dev): bump lint-staged from 15.4.2 to 15.4.3
  • docs: update logo image URL in README files

v1.4.1 - 25 January 2025

  • ci: update dependencies and adjust commitlint rule
  • chore(deps-dev): bump typescript-eslint from 8.18.0 to 8.20.0
  • chore(deps-dev): bump eslint from 9.16.0 to 9.18.0
  • chore(deps-dev): bump @eslint/js from 9.16.0 to 9.18.0
  • chore(deps-dev): bump globals from 15.13.0 to 15.14.0
  • chore(deps-dev): bump @commitlint/cli from 19.6.0 to 19.6.1
  • docs: update CHANGELOG.md

v1.4.0 - 11 December 2024

  • chore: release v1.4.0
  • chore(deps): bump all dependencies to latest versions
    • feat: add code size analyzer
  • docs: update CHANGELOG.md

New Features

  • feat: add code size analyzer @z0ffy

Chores And Housekeeping

  • chore: optimize @z0ffy

v1.3.2 - 3 December 2024

  • chore(deps): bump all dependencies to latest versions
  • chore(deps-dev): bump eslint from 9.15.0 to 9.16.0
  • chore(deps-dev): bump vite from 6.0.1 to 6.0.2
  • chore(deps-dev): bump @eslint/js from 9.15.0 to 9.16.0
  • chore(deps-dev): bump globals from 15.12.0 to 15.13.0
  • chore(deps): bump all dependencies to latest versions
  • chore(deps-dev): bump @types/node from 22.9.1 to 22.9.3
  • chore(deps-dev): bump typescript from 5.6.3 to 5.7.2
  • chore(deps): bump all dependencies to latest versions
  • chore: release v1.3.1

v1.3.1 - 19 November 2024

  • chore: release v1.3.1
  • docs: update README.md
  • chore: update doc
  • chore(deps-dev): bump eslint from 9.14.0 to 9.15.0
  • chore(deps-dev): bump @eslint/js from 9.14.0 to 9.15.0
  • chore: add auto-changelog
  • chore: update ci
  • chore: add lint
  • chore: update .gitignore
  • chore: update doc
  • chore(deps-dev): bump vite from 5.4.10 to 5.4.11
  • chore(deps-dev): bump @types/node from 22.8.7 to 22.9.0
  • chore(deps-dev): bump @types/node from 22.8.4 to 22.8.7

v1.3.0 - 4 November 2024

  • feat: upgrade to 1.3.0
  • feat: node_modules split chunk
  • chore(deps): bump all dependencies to latest versions
  • chore(deps-dev): bump vite from 5.4.9 to 5.4.10
  • chore(deps-dev): bump tsup from 8.3.0 to 8.3.5
  • chore(deps-dev): bump @types/node from 22.7.7 to 22.8.1
  • doc: update README.md
  • feat: changelog

v1.2.1 - 21 October 2024

  • feat: upgrade to 1.2.1
  • chore(deps-dev): bump vite from 5.4.8 to 5.4.9
  • chore(deps-dev): bump @types/node from 22.7.5 to 22.7.7
  • fix: esm __dirname
  • feature/add vitest
  • Update ts-check.yml
  • chore: optimize
  • chore(deps-dev): bump vite from 5.4.8 to 5.4.9
  • update dependabot.yml
  • Create ts-check.yml

v1.2.0 - 12 October 2024

  • feat: upgrade to 1.2.0
  • doc: update README.md
  • doc: update README.md
  • feat: rm max thread pool limit
  • doc: update README.md
  • Feature/multi threads
  • chore(deps-dev): bump typescript from 5.6.2 to 5.6.3
  • Update dependabot.yml
  • Create dependabot.yml
  • chore: rename alwaysLog to forceLog
  • Feature/string array
  • chore: update dev dependencies
  • doc: CHANGELOG.md

Chores And Housekeeping

  • chore: update .gitignore @z0ffy

v1.1.0 - 18 September 2024

  • Feature/add zh doc
  • fix: support apply option
  • fix: enable config

New Features

  • feat: add action @zoffy
  • feat: upgrade to 1.1.0 @zoffy

v1.0.9 - 12 September 2024

  • feat: upgrade to 1.0.9
  • Feature/support exclude node modules

v1.0.8 - 11 September 2024

  • feat: upgrade to 1.0.8
  • feat: optimize
  • Feature/excludes support regexp
  • chore: updated dependencies
  • docs: update README.md

v1.0.7 - 29 August 2024

  • feat: upgrade to 1.0.7
  • feat: upgrade to 1.0.7
  • chore: updated package.json
  • chore: updated dependencies
  • doc: update README.md

v1.0.6 - 23 August 2024

  • Feature/format time
  • feat: optimize log

v1.0.5 - 22 August 2024

  • feat: upgrade to 1.0.5

v1.0.4 - 21 August 2024

  • feat: upgrade to 1.0.4
  • feat: upgrade to 1.0.3

v1.0.2 - 29 July 2024

  • feat: upgrade to 1.0.2
  • doc: update README.md

v1.0.1 - 29 July 2024

  • feat: upgrade-to-1.0.1
  • feat: add default options
  • feat: add options
  • doc: change

v1.0.0

  • Feature/publish
  • feat: update README.md
  • feat: init
  • feat: init

New Features

  • feat: publish @ 
  • feat: publish @ 

General Changes

  • Initial commit @zoffy