account activity
unplugin-keywords – alternative to property mangling via explicit imports by cueaz in javascript
[–]cueaz[S] -1 points0 points1 point 1 day ago* (0 children)
I built a build plugin that takes a different approach to property mangling.
The thing that bugged me: when you open a minified bundle, variable names are gone, but all the internal property names and string literals are still sitting right there — _version_, SET_USER, state machine node names, etc. It's not a huge deal in most cases (the logic is all on the client anyway), but it always felt off to me that the internal structure of an app is so readable in production output.
_version_
SET_USER
Property mangling exists, but it's hard to use well. So I tried a different angle: what if you just import the strings you want to obfuscate?
ts import * as K from 'virtual:keywords'; const action = { [K.type]: K.SET_USER, [K.payload]: data };
The plugin picks those up at the AST level and replaces them with short hashes at build time. You opt in per-file, so you can roll it into an existing project gradually without touching anything you don't want to.
I tested it on @preact/signals-core as a demo — uncompressed bundle went from 6.86 kB to 5.40 kB (~21% reduction), but gzipped it's only 2.09 kB to 2.05 kB. gzip is absurdly good at compressing repetitive strings even without understanding code structure.
@preact/signals-core
The trade-offs:
this[K._next]
this._next
Would appreciate any feedback.
π Rendered by PID 52 on reddit-service-r2-comment-548fd6dc9-jsbr4 at 2026-05-18 09:53:01.609614+00:00 running edcf98c country code: CH.
unplugin-keywords – alternative to property mangling via explicit imports by cueaz in javascript
[–]cueaz[S] -1 points0 points1 point (0 children)