npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-bundle-obfuscator

v1.14.0

Published

JavaScript obfuscator plugin for Vite environments

Readme

vite-plugin-bundle-obfuscator

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

awesome-vite npm version npm downloads GitHub Release Date codecov GitHub License

📝 更新日志 · 🐛 报告问题 · ✨ 请求功能

⭐️ 特性

  • ✅ ⚡ 支持Vite项目中的JavaScript混淆。
  • ✅ 🚀 多线程支持,以获得更好的性能。
  • ✅ ⚙️ 可定制的混淆器选项,以满足您的需求。
  • ✅ 🔐 可选支持 JavaScript Obfuscator Pro API。
  • ✅ 🛡️ 自动排除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。
  • 库模式在构建后期的 generateBundle 中执行混淆。默认的 selfDefending: true 要求生成的代码不再被格式化或二次处理。 如果库会被下游项目再次打包、压缩或格式化,建议在构建库时设置 options: { selfDefending: false },并验证消费端的生产产物。 仅设置 build.minify: true 不能保证所有构建配置都兼容。
  • 库模式下,本插件应在其他会修改代码的 generateBundle(order: 'post')钩子之后执行。 同级钩子遵循最终插件顺序,还需考虑 Vite 的 enforce 排序。后续 generateBundle 或 writeBundle 再修改代码, 与 selfDefending: true 不兼容,应调整插件顺序,或在该构建流程中关闭 selfDefending。
  • 显式设置的 threadPool.size 必须是正整数;使用 threadPool: true 可按 CPU 数量分配线程。 非法线程数会使构建报错,不会静默跳过混淆。
  • 库模式中包含 [hash] 的文件名会计入混淆配置;使用随机 seed(默认)或 Pro API 时,hash 每次构建都会变化。 固定文件名仍需通过版本号或缓存失效策略更新。JavaScript 与对应的 sourcemap 应配套发布。
  • javascript-obfuscator 的部分转换(例如控制流混淆)会生成没有原始源码位置的辅助函数, 这些函数的异常栈帧即使使用合并后的 sourcemap,也可能无法映射到原始源码。

🌐 在线试用

✦ Vite - Vanilla ✦ Vite - Vue ✦ Vite - React ✦ Vite - PReact ✦ Vite - lit ✦ Vite - Svelte ✦ Vite - Solid ✦ Vite - 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 }
  pro: 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,
    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(allObfuscatorConfig)
  ]
};

// 简化配置
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()
  ]
};

🔐 JavaScript Obfuscator Pro API

Pro API 默认关闭。只有需要 javascript-obfuscator Pro 功能,例如 vmObfuscation 或 parseHtml 时才需要显式开启。

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

export default {
  plugins: [
    vitePluginBundleObfuscator({
      pro: {
        enable: true,
        apiToken: process.env.JAVASCRIPT_OBFUSCATOR_PRO_API_TOKEN,
        version: '5.0.3',
        timeout: 300000,
      },
      options: {
        vmObfuscation: true,
        vmBytecodeFormat: 'binary',
        compact: true,
      },
    }),
  ],
};

pro 只用于配置 Pro API 调用。所有混淆参数,包括 vmObfuscation、vmBytecodeFormat、optionsPreset、parseHtml 等 Pro 混淆参数,都继续写在 options 中。

🧵 Web Worker 支持

默认不会对 ?worker / new Worker(new URL(...)) 生成的 worker bundle 进行混淆。

启用 worker 混淆:

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

export default {
  plugins: [
    vitePluginBundleObfuscator({
      obfuscateWorker: true,
    }),
  ],
};

仅对 worker 额外排除某些文件:

vitePluginBundleObfuscator({
  obfuscateWorkerExcludes: [/comlink\\.worker.*\\.js$/],
});

🚀 性能比较

拥有 7000+ modules 和 400+ bundles 在 4C 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版本中扩展到当前类型) | | obfuscateWorker | 启用或禁用 Web Worker 产物混淆。 | boolean | { enable: boolean } | false | v1.10.0 | | obfuscateWorkerExcludes | 仅对 worker 额外排除(最终:excludes + obfuscateWorkerExcludes)。 | (RegExp | string)[] | [] | v1.10.0 | | pro | JavaScript Obfuscator Pro API 配置。 | false | { enable: boolean; apiToken?: string; version?: string; timeout?: number; onProgress?: (message: string, fileName: string) => void } | false | - | | 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