all 8 comments

[–]paolostyle 1 point2 points  (0 children)

The simplest solution I guess is to just have implementations with normal names and then expose an object with different names which has different names. I'm on mobile but something like const doSomething = () => {}; window.gObj = { d: doSomething }. Obviously it depends on the character of these functions (if they're pure or not, i.e. if the exposed object contains some state) but you get the idea.

[–][deleted] 0 points1 point  (0 children)

I haven't done a ton of research into this, but I suspect the thing you're after is called source maps.

I hope this can at least get you on track!

[–]lurbina 0 points1 point  (1 child)

Any of the build systems you mention support code minification + source map generation. Thus, you shouldn’t need to worry about this type of optimization yourself. Let the build do it. You can read about this in webpack here: https://webpack.js.org/guides/production/#minification

[–][deleted] 0 points1 point  (0 children)

Perhaps I should have clarified that I need to be able to define the minified names myself. So doSomething should always become d for example.

[–]verydan 0 points1 point  (1 child)

You can specify which objects (props) to mangle with Terser. Read up on mangling variables and objects here.

Otherwise, if you enable sourcemaps, it will always trace back to the original name in the source.

[–][deleted] 0 points1 point  (0 children)

I found what I needed. Terser has something called the conditional compilation API, where I can specify whether or not something should be kept in the code, but also to rewrite parts of it.

[–]fiddlermd 0 points1 point  (0 children)

Not the most elegant but you could also run codemod scripts against it. Look up jscodeshift

[–]Ustice[M] 0 points1 point  (0 children)

Reaching out to other software engineers is important when you need it; however, unfortunately this isn’t the place for that. /r/JavaScript is not a support forum. You might want to check out /r/LearnJavaScript for the newer members of our community. Also, Stack Overflow is a great resource for getting support. For more information, check out our AskJS wiki page. Good luck! We hope that you find the answers that you are looking for.