Obfuscation and Compression of Deno Bundles

Viewed 438

In WebPack, when I produce a bundle it obfuscates and compresses that bundle.

In deno, the bundler produces formatted code that is way more readable. I don't see any options for obfuscation or compression.

In deno, how would I accomplish an obfuscated and compressed bundle? I need something like WebPack that doesn't involve Visual Studio Code. What are some options? Do I just use node tools for this?

1 Answers

One way I can suggest is to use a regex expression to systematically remove anything useful to a programmer or would be inspect element users.

I don't have the greatest example but this removes 99% of whitespace as well as all lines. A more aggressive approach would also rename most user-defined variables to a bunch of jargon like 'a', 'b', or 'aB'

const obfuscated = originalCode.replace(/\s+/g, " ").replace(/\n/g, "").replace(/\/\/# sourceMappingURL.*$/, "");

The last expression ran removes information about the bundle that would include the original files and imports which may otherwise pose a security risk if you're sending it to clients.

Though the question was asked 2 years ago I hope somebody finds this helpful.

Related