A directive is a comment that changes AfterPack's protection for the code it marks. Everything else in the build keeps the configuration you set for the whole program. Directives are a Pro feature.
Writing one
A directive is a block comment starting with @afterpack. Alone on its line, it applies to everything up to the matching /* @afterpack end */. Followed by code on the same line, it applies to the rest of that line.
/* @afterpack preset=hard */
function checkLicense(token) {
return verifySignature(token, PUBLIC_KEY);
}
/* @afterpack end */
const apiKey = /* @afterpack preset=extreme */ "YOUR_SECRET";Keys are the dotted names from the Configuration page, space-separated: /* @afterpack preset=hard inflation.max=6 */. A boolean key alone means true. Directives apply to the code they wrap and nothing else: not to functions called from it, and not to imports.
What you can set
Any option that applies per region. Each one links to its definition, and the directive tab there shows the exact spelling.
Any other option in a directive is ignored and reported as info. An unknown key or a malformed directive is an error.
When to use one
- Mark the code that matters most, such as license checks, anti-tamper logic or a bundled secret, with
preset=extreme. The rest of the program stays lighter and smaller. - Mark code that must stay readable or fast, such as a hot loop or a third-party snippet, with
skipor a lowerpreset.
What to mark
| Asset | Directive | Why |
|---|---|---|
| License / entitlement checks | preset=hard | A single patched bit gives away your software. Pair with transforms.comparisonHardening.enabled. |
| Payment validators | preset=hard | Tampering is the threat, not just reading. |
| Anti-cheat / anti-bot logic | preset=hard or preset=extreme | Raises the cost and cadence of cheat development. Opponents have time and motive, so pair with server-authoritative validation. |
| Hardcoded secrets you can't move server-side | /* @afterpack preset=extreme */ inline, before the literal | Best removed entirely, but some always slip through. preset=extreme makes recovery expensive, and the literal still exists in the output. Keep a literal your code compares against out of the output entirely with transforms.comparisonHardening.enabled. For one that already shipped, see If you shipped a secret by accident. |
| Proprietary algorithms (pricing, routing, ML glue) | /* @afterpack preset=extreme */ … /* @afterpack end */ around the core function | This is your most valuable code. Maximum complexity target and the constants floor on. |
Apply the directive at the smallest scope that covers the asset. Marking a 500-line file preset=extreme inflates the whole bundle for little gain.
Checking what was applied
The Protection Map shows every region a directive produced and what was applied inside it. A directive that was read but had no effect appears in the build's diagnostics.
Free builds
A Free engine applies one configuration to the whole program. A directive in a Free build stops the build with a message explaining how to sign in.