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

output-obfuscator-plugin

v1.0.4

Published

CLI tool for obfuscating URLs in JavaScript/TypeScript files

Readme

Output Obfuscator Plugin

CLI 工具,用于混淆 JavaScript/TypeScript 文件中的 URL 字符串。

特性

  • 两种混淆模式:Simple(URL 混淆)和 Advanced(完整混淆)
  • 支持 TypeScript 配置文件
  • 零配置开箱即用
  • 通过 npx 直接运行,无需安装

快速开始

基本使用

直接运行:

npx -y output-obfuscator-plugin@latest ./dist

集成到构建流程

package.json 的 scripts 中添加 postbuild 脚本,构建完成后自动执行混淆:

{
  "scripts": {
    "build": "vite build",
    "postbuild": "npx -y output-obfuscator-plugin@latest ./dist"
  }
}

提示-y 参数让 npx 自动同意安装,适用于 CI/CD 环境(GitHub Actions、GitLab CI 等)。

配置文件(可选)

在项目根目录创建 output_obfuscator.tsoutput_obfuscator.js

// output_obfuscator.ts
import type { CLIConfig } from 'output-obfuscator-plugin'

export default {
  mode: 'simple',
  extensions: ['.js'],
  exclude: ['**/vendor/**'],
  logLevel: 'info'
} satisfies CLIConfig

配置参数

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | mode | 'simple' \| 'advanced' | 'simple' | 混淆模式 | | extensions | string[] | ['.js', '.ts', '.jsx', '.tsx'] | 处理的文件扩展名 | | exclude | string[] | ['**/node_modules/**'] | 排除的文件 Glob 模式 | | urlPattern | RegExp | 见下方 | URL 匹配正则 | | obfuscatorOptions | ObfuscatorOptions | - | Advanced 模式配置 | | logLevel | 'silent' \| 'info' \| 'debug' | 'info' | 日志级别 |

默认 URL 匹配正则

/(?:https?|wss?):\/\/[^\s"'`\)]+/g

混淆模式

Simple 模式

专注于 URL 字符串混淆,随机使用以下三种方式之一:

| 方式 | 示例 | |------|------| | Base64 | atob("aHR0cHM6Ly9leGFtcGxlLmNvbQ==") | | Unicode | "\u0068\u0074\u0074\u0070\u0073..." | | CharCodes | String.fromCharCode(104, 116, 116, 112, ...) |

优点:轻量、快速、对代码体积影响小

Advanced 模式

基于 javascript-obfuscator,提供完整的代码混淆功能。

预设级别

| 预设 | 特性 | |------|------| | low | 字符串数组(50%),紧凑格式 | | medium | 控制流扁平化(50%),字符串数组+Base64(75%) | | high | 控制流扁平化(75%),死代码注入(40%),对象键转换,Unicode 转义 |

配置示例

基础配置

// output_obfuscator.ts
export default {
  mode: 'simple',
  extensions: ['.js'],
  logLevel: 'info'
}

使用 Advanced 模式

// output_obfuscator.ts
export default {
  mode: 'advanced',
  extensions: ['.js'],
  exclude: ['**/vendor/**', '**/lib/**'],
  obfuscatorOptions: {
    preset: 'medium'
  }
}

自定义 obfuscator 配置

// output_obfuscator.ts
export default {
  mode: 'advanced',
  obfuscatorOptions: {
    compact: true,
    controlFlowFlattening: true,
    controlFlowFlatteningThreshold: 0.5,
    stringArray: true,
    stringArrayEncoding: ['base64']
  }
}

完整配置项参考 javascript-obfuscator 文档

自定义 URL 匹配

// output_obfuscator.ts
export default {
  mode: 'simple',
  urlPattern: /https:\/\/api\.[^\s"']+/g  // 只匹配 api. 开头的 URL
}

兼容性

| 环境 | 版本要求 | |------|----------| | Node.js | >= 18 |

浏览器环境

  • Simple 模式的 Base64 混淆需要 atob() 支持(IE10+)
  • Unicode 和 CharCodes 方式兼容所有浏览器

注意事项

  1. 仅在生产环境使用 - 开发环境启用会影响调试体验
  2. 性能影响 - Advanced 模式的 high 预设会显著增加代码体积和执行时间
  3. 建议从低级别开始 - 先用 lowmedium 测试,再根据需要提升
  4. Source Map - 混淆后 Source Map 将失效

⚠️ 免责声明

本工具仅供学习和测试使用,可能存在未知问题。

使用前请务必:

  1. 在测试环境充分验证混淆后的代码功能
  2. 确保混淆后的代码运行正常
  3. 不要直接在生产环境使用未经验证的混淆代码

作者不对因使用本工具导致的任何问题承担责任。

License

MIT