farm-plugin-obfuscate
v0.6.0
Published
Negotiated obfuscation plugin for FarmFE — selectively obfuscate functions, classes, and code blocks via compile-time markers
Maintainers
Readme
farm-plugin-obfuscate
Negotiated obfuscation plugin for FarmFE — selectively obfuscate code via compile-time markers.
Install
npm install farm-plugin-obfuscateConcept
Unlike full-file obfuscators, this plugin lets you mark exactly which code gets obfuscated — at function, class, variable, or block level. Unmarked code stays readable. This is "negotiated" obfuscation: you negotiate with the compiler about what to protect.
Usage
import obfuscate from 'farm-plugin-obfuscate'
export default {
plugins: [
obfuscate({
defaultLevel: 'medium',
seed: 42, // deterministic obfuscation
}),
],
}Markers
@obfuscate — Decorator (function/class/variable)
@obfuscate
function secretAlgorithm() { /* fully obfuscated */ }
@obfuscate('light')
function helper() { /* identifier renaming only */ }
@obfuscate('full')
class CryptoEngine { /* maximum obfuscation */ }
@obfuscate('none')
function debugLog() { /* explicitly excluded — stays readable */ }$obfuscate(() => { ... }) — Block-level
// Obfuscate a specific code block
const result = $obfuscate(() => {
const key = 'secret-key-12345'
return encrypt(data, key)
})
// Light obfuscation variant
const val = $obfuscate.light(() => computeHash(input))Obfuscation Levels
| Level | Renaming | String Encoding | Control Flow | Dead Code |
|-------|----------|-----------------|--------------|-----------|
| none | ✗ | ✗ | ✗ | ✗ |
| light | ✓ (mangled) | ✗ | ✗ | ✗ |
| medium | ✓ (hex) | ✓ (base64) | ✗ | ✗ |
| full | ✓ (hex) | ✓ (rc4) | ✓ | ✓ |
Options
defaultLevel— Default obfuscation level for@obfuscatewithout explicit level. Default:'medium'obfuscateAll— Obfuscate entire files (no decorator needed).@obfuscate('none')excludes specific declarations. Default:falseseed— Seed for deterministic/reproducible obfuscationexclude— File path patterns to skip entirely
HMR
Re-obfuscates on file changes.
License
MIT
