7 ms·
Interesting. I can definitely relate. As an author of a proprietary application written in web technologies, it's easy to be envious of compiled languages. Thi
by catchaway_4v93a 5y ago
Interesting. I can definitely relate. As an author of a proprietary application written in web technologies, it's easy to be envious of compiled languages.
This is my recipe for minification:
1. Apply a convention where all class properties and methods have to end with a trailing underscore (it's trivial to make an Eslint rule to enforce it)
2. Use 2 minification tools in following order: Closure Compiler (simple optimizations mode), then Terser for best output.
3. Configure Terser mangle.properties.regex: /_$/
4. If it's a desktop app, use Bytenode for Node.js processes (cannot be used for the renderer)
I also consider creating a tool to mangle string literals if they match a pattern. I.e. all string literals in the code that end with __ would be mangled. The benefit is that all internal event names and what not will not be visible.
Yep, it's not going to hide it completely, but it's just that much harder to RE and understand when there is pretty much nothing descriptive in plain English left in the code (except error messages and third party libraries).
Also I had this idea a few years earlier in a previous application where I did not use a module bundler. It was good old ES5 with files merged with Gulp and using prototype pattern. For those who do not know, prototype pattern is essentially like a class, but it's properties and methods do not have to be enclosed in one block. I did not implement it, but theoretically, it would be possible to create a mixer that would take all these prototype classes and their properties and create an output where all properties and methods from all classes would be output in a completely random order, all mixed together. Though looking back, it's probably not such a bright idea, as it would be possible to create an AST program that would reorder the methods back in place.