# Obfuscation के presets

minify से extreme तक सुरक्षा के पाँच स्तर, हर एक जो complexity target सेट करता है, और zero-config default (light) पहले से क्या गारंटी देता है।

Source: https://www.afterpack.dev/hi/docs/presets

Preset transforms का एक नामित set है जिसकी size और runtime लागत ज्ञात है। भारी preset ज़्यादा transformation लगाता है; यह सुरक्षा में मापी गई बढ़त नहीं है। एक नाम [complexity target](https://www.afterpack.dev/hi/docs/config#complexity) तय करता है; output size उसी target से तय होता है। [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) को सीधे set करने पर target override हो जाता है, और सीधे set की गई value हमेशा हर token पर लागू होती है, `light` पर भी।

*(preset ladder diagram — see https://www.afterpack.dev/docs/presets)*

## सीढ़ी

| Preset | [`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) | सामान्य gzipped size | [String floor](https://www.afterpack.dev/hi/docs/config#strings-encode) | इसे कब चुनें |
|---|---:|---:|:---:|---|
| `minify` | `0` | `1.09x` से `1.17x` | बंद | कोई obfuscation नहीं। Identifiers rename किए जाते हैं और code compress किया जाता है; string literals पढ़ने योग्य रहते हैं। |
| `light` | `5` | `1.29x` से `1.60x` | चालू | **डिफ़ॉल्ट।** `minify` में string encoding जोड़ता है और syntax को दोबारा लिखता है, बिना किसी संरचनात्मक layer के। ज़्यादातर projects के लिए सही baseline। |
| `medium` | `7` | `6.04x` से `8.33x` | चालू | ऐसा production code जिसे आप समझने में उल्लेखनीय रूप से कठिन बनाना चाहते हैं। |
| `hard` | `12` | `6.62x` से `9.23x` | चालू | वह code जो अहम है: pricing, gating, license checks, client-side business logic। |
| `extreme` | `25` | `8.25x` से `11.19x` | चालू | सबसे ऊँची लागू complexity। इसे पूरे bundle के बजाय किसी एक फ़ाइल या [region](https://www.afterpack.dev/hi/docs/directives#what-you-can-set) पर लक्षित करें। |

ऊपर दिए आँकड़े पाँच असली, पहले से minified production bundles पर, AfterPack 0.2.6 के साथ 2026-10-16 को, पहले से minified उसी फ़ाइल के मुक़ाबले gzipped output का मापा गया आकार हैं; तरीक़ा [Performance](https://www.afterpack.dev/hi/docs/performance#output-size) पर है।

किसी भी positive target के लिए string floor चालू रहता है।

## डिफ़ॉल्ट `light` है

बिना किसी [`--preset`](https://www.afterpack.dev/hi/docs/config#preset) के [`npx afterpack@latest dist/`](https://www.afterpack.dev/hi/docs/cli#usage) चलाएँ, या एक [plugin](https://www.afterpack.dev/hi/docs/frameworks) install करके कुछ भी configure न करें, और आपको `light` मिलता है।

```bash
npx afterpack@latest dist/
```

```bash
npx afterpack@latest dist/ --preset=hard    # step up
```

[Flags](https://www.afterpack.dev/hi/docs/config) अपनी value को `=` से जोड़ते हैं। Space से अलग की गई value को एक अज्ञात flag के रूप में अस्वीकार कर दिया जाता है।

`light` zero-config floor है। हर string literal जिसे यह फिर से लिख सकता है, एक runtime decoder से होकर जाता है। यह identifiers को rename करता है और syntax को दोबारा लिखता है, और कोई संरचनात्मक layer नहीं जोड़ता। Engine 0.2.3 से, `minify` और `light` पर loops को अब callback helpers में नहीं बदला जाता, जिससे hot loops में इन helpers की वजह से होने वाली 2-5x धीमी गति ख़त्म हो जाती है। `light` पर property और global names अब भी encoded constants से होकर जाते हैं, जिसकी बहुत hot code में कुछ लागत होती है। कुछ strings हर preset पर पढ़ने योग्य रहती हैं: directive prologues, `typeof` के comparands, वे property names जिनकी runtime को ज़रूरत है, और export names। [Protection Map](https://www.afterpack.dev/hi/docs/protection-map) उन्हें सूचीबद्ध करता है, और engine हर build पर उनकी गिनती और कुल bytes रिपोर्ट करता है। Preset को `medium` या उससे ऊपर बढ़ाना हर token पर संरचनात्मक काम जोड़ता है: inflation, control-flow reshaping, और एक साझा runtime value से keyed strings और integers। यह string की पठनीयता नहीं बदलता, जो पहले से ही अपने floor पर है।

`minify` वह एक पायदान है जो floor को बंद कर देता है। Engine 0.2.3 से, यह केवल identifiers को rename करता है और code को compress करता है, जिसमें कोई obfuscation लागू नहीं होती। Engine 0.2.2 `minify` पर syntax को भी दोबारा लिखता था।

## Size का budget

हर output में engine का निश्चित runtime overhead होता है, यानी decoders और integer-expression interpreter, इसलिए कुछ सौ bytes की छोटी फ़ाइल ऊपर दी सीमाओं से भी आनुपातिक रूप से बड़ी निकलती है। अनुपात किसी असली bundle पर पढ़ें, किसी छोटी फ़ाइल पर नहीं।

[`inflation.max`](https://www.afterpack.dev/hi/docs/config#inflation-max) डिफ़ॉल्ट रूप से unset है, इसलिए complexity target अकेले output size तय करता है। इसे स्वयं तभी सेट करें जब आपके पास एक वास्तविक size budget हो जिसे पार करने के बजाय आप build को विफल होने देना पसंद करें। किसी स्पष्ट रूप से सेट किए मान तक पहुँचना एक error है: [`DIAG_SIZE_CAP_REACHED`](https://www.afterpack.dev/hi/docs/diagnostics#complete-reference), कोई output नहीं, CLI से [exit `3`](https://www.afterpack.dev/hi/docs/diagnostics#exit-codes), और plugin से build fail। Engine 0.2.3 से, उसकी जगह कम-सुरक्षित output कभी नहीं लिखा जाता: तैयार फ़ाइल को सीमा से जाँचा जाता है, और string encoding हमेशा पहले पूरी होती है। Engine 0.2.2 में एक तंग सीमा string encoding को पहले ही रोक सकती थी और कुछ strings को पढ़ने योग्य छोड़ सकती थी।

## Target को सीधे सेट करना

[`complexity`](https://www.afterpack.dev/hi/docs/config#complexity) एक असीमित गैर-ऋणात्मक संख्या है। [`--complexity=200`](https://www.afterpack.dev/hi/docs/config#complexity) एक मान्य [Free-tier](https://www.afterpack.dev/hi/docs/tiers) override है, जो `extreme` के सेट किए मान से कहीं आगे है।

```bash
npx afterpack@latest dist/ --preset=hard --complexity=40
```

यह `hard` है जिसका complexity target 40 पर override किया गया है; preset का बाक़ी हिस्सा नहीं बदलता। [`--complexity`](https://www.afterpack.dev/hi/docs/config#complexity) को एक preset का नाम देना एक error है।

## एक region पर preset लागू करना

`--preset` पूरे bundle को एक समान सेट करता है; यह [Free](https://www.afterpack.dev/hi/docs/tiers) है। किसी एक function या फ़ाइल पर एक भारी preset केंद्रित करना एक [Pro](https://www.afterpack.dev/hi/docs/pro#what-pro-buys) feature है, जो एक [source directive](https://www.afterpack.dev/hi/docs/directives) के ज़रिए होता है:

```js
/* @afterpack preset=extreme */
function pricingEngine(plan, region) {
  return resolve(plan, region);
}
/* @afterpack end */
```

Directives [केवल block comments](https://www.afterpack.dev/hi/docs/directives#writing-one) होते हैं, जिन्हें plugin आपके source से पढ़ता है। Grammar और tier के नियमों के लिए [Directives](https://www.afterpack.dev/hi/docs/directives) देखें।

## आगे

- [Configuration](https://www.afterpack.dev/hi/docs/config): हर key जिसे एक preset छूता है।
- [CLI reference](https://www.afterpack.dev/hi/docs/cli): वे flags जो एक preset चुनते हैं।
- [Directives](https://www.afterpack.dev/hi/docs/directives): एक span के लिए [`skip`](https://www.afterpack.dev/hi/docs/config#skip) या [`preset=<name>`](https://www.afterpack.dev/hi/docs/config#preset)।
- [AfterPack कैसे काम करता है](https://www.afterpack.dev/hi/docs/concepts): एक static reader के विरुद्ध ऊँचा target वास्तव में क्या दिलाता है।
- [Best practices](https://www.afterpack.dev/hi/docs/best-practices): किसे और मज़बूत करें और किसे अछूता छोड़ें।
