@afterpack/core

中文文档
1.0.2发布于 2026/10/28SEE LICENSE IN LICENSETypeScriptESM + CJS零依赖近 30 天下载 2322

JavaScript obfuscator engine for Node: protect your JavaScript source code in any build, locally or with AfterPack Pro

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Errors
  4. Pro
  5. Platforms
  6. License

@afterpack/core

The engine behind AfterPack, the JavaScript obfuscator. It runs in Node, takes JavaScript and returns obfuscated JavaScript, so you can protect your JavaScript source code in any build.

Most people want the CLI (npx afterpack) or a framework plugin instead. Start with the quickstart or the CLI reference. Use this package when you are writing your own build step or tool.

Install

npm install @afterpack/core

Needs Node 18 or later. The prebuilt binary for your platform installs with it.

Usage

import { obfuscate, obfuscateAll, version } from "@afterpack/core";

const result = await obfuscate('console.log("hello")', { preset: "hard" });
result.code;  // the obfuscated source
result.bytes; // the same output as bytes, ready to write

// Several files at once. Results come back in input order.
const results = await obfuscateAll([
  { path: "dist/app.js", source: appSource },
  { path: "dist/vendor.js", source: vendorSource, sourceMap: vendorMap },
]);

await version(); // "0.1.0"

obfuscate accepts a string, a Uint8Array, or a file object { path, source, sourceMap, sourceType }, where sourceMap is the file's existing map to chain and sourceType ("auto", "module" or "script") overrides the build's for that file. Each result has code, bytes, sourceMap and diagnostics.

The second argument is the config: preset, complexity, sourceMap, identifiers, strings and more. Unknown keys are rejected, so a typo fails loudly. See the configuration reference.

A tool that wraps AfterPack can name itself to the cloud in an optional third argument, obfuscate(source, config, { client: "my-tool/1.0.0" }). It never changes the output.

Errors

If a build can't ship safely, the call throws. That covers an invalid config, a blocking diagnostic, or output that would go out unprotected. The error carries the engine's diagnostics:

import { obfuscate, ObfuscationError } from "@afterpack/core";

try {
  await obfuscate(source);
} catch (err) {
  if (err instanceof ObfuscationError) console.error(err.diagnostics);
  throw err;
}

Pro

Without a key, all of Free runs on your machine, with every preset, no account and no network call. Set your Pro key in the AFTERPACK_KEY environment variable, or pass key in the config (which wins over the variable), and the same call runs the build in AfterPack's cloud instead. Pro adds per-file and per-region direction through directives, stores each build's Protection Map, and shows your builds in the dashboard. It also offers two opt-in hardening settings, transforms.selfIntegrity and transforms.comparisonHardening, both off by default (details). It does not make any transform stronger. Read more about AfterPack Pro or see pricing.

Why this matters now: AI agents deobfuscate JavaScript that older tools protect. See how AfterPack compares to javascript-obfuscator and Jscrambler.

Platforms

  • macOS: arm64 (Apple Silicon), x64
  • Linux (glibc): x64, arm64
  • Windows: x64

Alpine and other musl-based Linux have no native binary yet: use a glibc-based image. On those hosts, and anywhere a native addon can't load (such as a Cloudflare Worker), @afterpack/wasm runs the same obfuscate API.

License

Free for any use, including commercial and CI, with no limits, and the output is yours. You can't redistribute the binary on its own, build a competing obfuscation product or service on it, or reverse engineer it. See the AfterPack Engine License.

Questions and feedback: get in touch. Bug reports: GitHub.

版本与发布记录

@afterpack/core 共发布 14 个版本,首次发布于 2026/01/08;过去 12 个月发布了 14 个版本。

版本发布日期距今
1.0.2latest2026/10/2810 天前
1.0.02026/10/2315 天前
0.2.82026/10/1919 天前
0.2.72026/10/1721 天前
0.2.62026/10/1622 天前
0.2.52026/10/1424 天前

关于 @afterpack/core 的常见问题

@afterpack/core 是什么?

JavaScript obfuscator engine for Node: protect your JavaScript source code in any build, locally or with AfterPack Pro

如何安装 @afterpack/core?

在项目目录运行 npm install @afterpack/core,或使用 pnpm add / yarn add / bun add。

@afterpack/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@afterpack/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@afterpack/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@afterpack/core 可以商用吗?

@afterpack/core 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@afterpack/core 的下载量有多少?

根据 npm 官方下载统计,@afterpack/core 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,322 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@afterpack/core 还在维护吗?

最新版本 1.0.2 发布于 2026/10/28(10 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/01/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。