Only mangling services one to trigger an enthusiastic underscore is actually a good heuristic since the typical JS code doesn’t generally include identifiers in that way. If you wish to prevent mangling names particularly __defineGetter__ you can consider utilizing an even more cutting-edge normal term including [^_]_$ (i.e. need produce a low-underscore accompanied by a keen underscore).
This might be a unique mode in lieu of becoming part of the minify form since it is a harmful conversion that will not works on the haphazard JavaScript password. They simply works if the considering regular expression matches each of the newest services that you like mangled and does not suits one of one’s features you don’t need mangled. In addition only really works if you do not less than one activities source a great mangled possessions ultimately. Including, it indicates you can not have fun with obj[prop] to source a home where prop is a series who has the newest assets label. Specifically the next syntax constructs will be the simply of those entitled to possessions mangling:
While using this particular aspect, understand that property names are merely constantly mangled contained in this an individual esbuild API call yet not across esbuild API phone calls. Per esbuild API name really does a separate assets mangling operation thus returns files from a couple of various other API phone calls es, that may cause the ensuing code to act wrongly.
By default, esbuild doesn’t modify the contents of string literals. This means you can avoid property mangling for an individual property by quoting it as a string. However, you must consistently use quotes or no quotes for a given property everywhere for this to work. For example, print(< foo_:>.foo_) will be mangled into print(< a:>.a) while print(< 'foo_':>[’foo_’]) will not be mangled.
If you need to own esbuild in order to including mangle the newest content from sequence literals, you can clearly allow one to conclusion similar to this:
If you like to prohibit certain properties out of mangling, you could potentially set aside these with an extra means. Such as, which uses the conventional expression ^__.*__$ to help you reserve every properties you to start and you will stop having one or two underscores, like __foo__ :
Complex access to the home mangling function concerns storage the mapping from fresh identity to help you mangled identity from inside the a persistent cache. Whenever permitted, all of the mangled assets renamings try recorded on cache during the first build. After that yields reuse the latest renamings kept in the latest cache and create extra renamings when it comes to recently-extra properties. It’s a number of effects:
Brand new cache serves as a listing of most of the features that were mangled. You can search they to find out if you’ll find people unexpected possessions renamings.
You could disable mangling to have individual qualities by mode the newest renamed worthy of so you’re able to not true as opposed to so you can a string. This might be just as the set-aside props setting however, on a per-property basis.
You might make certain consistent renaming anywhere between stimulates (age.grams. a main-thread document and you may an internet personnel, or a collection and a plugin). Versus this particular aspect, each build should do a separate renaming process in addition to mangled property brands more than likely would not be uniform.
When we require customRenaming_ become rebranded to help you cR_ so we don’t want disabledRenaming_ to-be renamed whatsoever, we can ticket the next mangle cache JSON so you can esbuild:
This informs esbuild to create certain metadata about the generate in JSON format. Another example sets brand new metadata inside a document called meta.json :
These details may then feel examined by the most other tools. Such as for example, package pal can also be consume esbuild’s metadata structure and you will makes an effective treemap visualization of your own segments on the bundle and just how far area each of them uses up.