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-electron-obfuscator

v1.0.0

Published

electron-vite 代码混淆插件:在 renderChunk 阶段混淆最终产物,按体积自适应强度,保留 Vite 动态 import 路径字符串,避免懒加载/可选链运行时崩溃。

Readme

vite-plugin-electron-obfuscator

electron-vite(及普通 Vite)项目设计的代码混淆插件:在 renderChunk 阶段混淆最终产物,按 chunk 体积自适应强度,并保留 Vite 动态 import 路径字符串,避免懒加载路由 / 可选链在运行时崩溃。

为什么不用通用混淆插件

桌面应用的混淆有几个"必须踩过才知道"的坑,本插件已默认规避:

  • 保留动态 import 路径字符串\.js$^\./ 等):否则懒加载路由 import('./xxx.js') 会拿到被切碎拼错的文件名而加载失败。
  • 关闭 splitStrings:它正是切碎 Vite 动态 import 字面量的元凶。
  • 关闭 controlFlowFlattening:会把 release?.() 这类可选链调用拆成"查表→调用",查表失败即 _0x... is not a function 崩溃。
  • 超大 chunk 自动轻量化(默认 >1.5MB):避免过度改写 vendor 运行时行为。

安装

npm i -D vite-plugin-electron-obfuscator

用法

renderer(渲染进程)

// electron.vite.config.ts
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite';
import vue from '@vitejs/plugin-vue';
import { obfuscateChunks } from 'vite-plugin-electron-obfuscator';

export default defineConfig(() => {
  const isWindowsBuild = process.env.BUILD_TARGET === 'win';

  // main/preload 保护:mac/linux 走字节码,windows 走 JS 混淆兜底
  // (Windows 下 V8 字节码历史上有 CRLF/路径/asar 锁兼容问题)
  const mainPreloadProtection = isWindowsBuild
    ? [obfuscateChunks({ name: 'obfuscate-main-preload' })]
    : [bytecodePlugin({ protectedStrings: ['password', 'secret', 'key', 'token'] })];

  return {
    main: { plugins: [externalizeDepsPlugin(), ...mainPreloadProtection] },
    preload: { plugins: [externalizeDepsPlugin(), ...mainPreloadProtection] },
    renderer: {
      build: {
        rollupOptions: {
          output: {
            // 用 hash 文件名隐藏业务模块语义
            chunkFileNames: 'assets/[hash].js',
            entryFileNames: 'assets/[hash].js',
            assetFileNames: 'assets/[hash][extname]',
          },
        },
      },
      plugins: [vue(), obfuscateChunks()],
    },
  };
});

bytecodePluginelectron-vite 提供,本插件不重复封装;mac/linux 主进程优先用字节码(更强),仅 Windows 构建用 JS 混淆兜底。

普通 Vite 项目

import { obfuscateChunks } from 'vite-plugin-electron-obfuscator';
plugins: [vue(), obfuscateChunks()]

选项

| 选项 | 类型 | 默认 | 说明 | |---|---|---|---| | name | string | 'vite-plugin-electron-obfuscator' | 插件名(多实例区分) | | enable | boolean | true | 关闭则跳过混淆 | | lightThreshold | number | 1_500_000 | 超过该字节数的 chunk 走轻量预设 | | reservedStrings | string[] | — | 追加保留字符串(正则) | | reservedNames | string[] | — | 追加保留标识符(正则) | | heavyOptions | ObfuscatorOptions | — | 深度覆盖重度预设 | | lightOptions | ObfuscatorOptions | — | 深度覆盖轻量预设 |

也导出了 OBFUSCATOR_HEAVY / OBFUSCATOR_LIGHT / DEFAULT_RESERVED_STRINGS / DEFAULT_LIGHT_THRESHOLD 供高级自定义。

⚠️ 注意

  • 不要通过 heavyOptions 打开 controlFlowFlatteningsplitStrings:它们会破坏可选链调用与动态 import,引发运行时崩溃。
  • main/preload 用字节码时需本机有可用的 Electron;CI 上若无 Electron,建议走 BUILD_TARGET=win 的 JS 混淆分支。

License

MIT