Skip to main content
Run property mangling by setting transforms.mangleProperties. Passing true selects every eligible non-built-in property. An options object lets you restrict that property selection.
obfuscate.mjs
A caller, another bundle, JSON payload, template, or framework can still use the original property name. Restrict mangling to properties whose reads and writes you control.

Choose a selection strategy

Use regex for a private naming convention. This example selects names ending in _ and reserves one public exception.
Regex selection

Roll it out safely

1

Find every use

Identify every file, caller, serialized value, and runtime lookup that can read the selected properties.
2

Select a narrow set

Start with a private naming rule, explicit annotations, or a reviewed cache. Do not begin with mangleProperties: true across a public interface.
3

Reserve external names

Add framework hooks, serialized keys, public methods, and reflective lookups to reserved.
4

Share mappings across files

Reuse one Map<string, string> through cache when separately obfuscated files exchange selected properties.
5

Test external consumers

Run integration tests against the obfuscated artifacts, including consumers that are not part of the input string.

builtins

Type: boolean
Default: false
Reserves known JavaScript and DOM property names when false.
Setting builtins: true can rename runtime or browser APIs such as collection methods and DOM properties. Use it only when those names cannot refer to platform objects.

cache

Type: Map<string, string>
Default: a new map for the call
Reuses mappings across calls and receives new mappings. Keys and values must be strings. Outputs must be unique and cannot be __proto__, constructor, or prototype.
Shared cache

debug

Type: boolean | string
Default: false
Keeps the source name visible. true produces _$source$_. A value such as debug: 'DEV' produces _$source$DEV_. Collisions fall back to the configured generator.

keepQuoted

Type: boolean | 'strict'
Default: false

nameGenerator

Type: (index: number) => string
Default: the configured string generator
Receives a zero-based ordinal for each candidate and takes precedence over stringGeneratorMode. It must eventually return an available, nonnumeric string. The transform throws after 100,000 rejected candidates.

onlyAnnotated

Type: boolean
Default: false
Limits mangling to names marked with the exact standalone comment /*@__MANGLE_PROP__*/ or /*#__MANGLE_PROP__*/. Mark standalone property strings with the exact comment /*@__KEY__*/ or /*#__KEY__*/. Annotations bypass regex, but not reserved, and never appear in the generated output.

onlyCache

Type: boolean
Default: false
Limits selection to source names already in cache.

regex

Type: RegExp | string
Default: all eligible names
Selects matching names. Strings are compiled with new RegExp(value). The transform resets lastIndex before each test. Numeric names are never selected.

reserved

Type: readonly string[]
Default: []
Excludes source names and prevents the generator from emitting them. It takes precedence over regex, annotations, and cache selection.

stringGeneratorMode

Type: a string generator mode
Default: the top-level mode
Overrides the top-level mode for property names. nameGenerator takes precedence.

undeclared

Type: boolean
Default: false
Includes unquoted accesses rooted at undeclared identifiers. Bracket-string accesses are candidates either way.

Names that always stay unchanged

The transform retains private class names, class constructor syntax, object-literal __proto__ setters, and names that would collide with retained properties.

Mangle-properties transform

See the transform’s behavior and a before-and-after example.

Configure transforms

Fit property mangling into a complete ObfuscatorOptions object.
Last modified on August 26, 2026