Just mangling properties you to definitely cause an enthusiastic emphasize try a reasonable heuristic since normal JS password doesn’t generally consist of identifiers like that. If you would like avoid mangling brands such as for example __defineGetter__ you can consider using a more advanced normal term including [^_]_$ (i.elizabeth. need certainly to result in a non-emphasize followed closely by an enthusiastic emphasize).
When using this particular feature, just remember that , possessions labels are merely continuously mangled inside just one esbuild API call however all over esbuild API calls. For each esbuild API call do an independent property mangling procedure thus efficiency data files created by a couple of different API calls es, that could cause the ensuing password to act incorrectly.
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 want getting esbuild in order to in addition to mangle the newest articles off sequence literals, you can clearly allow one decisions along these lines:
If you’d like in order to exclude certain characteristics out of mangling, you might put aside them with a supplementary setting. Such as, which uses the regular term ^__.*__$ so you’re able to set aside the features one initiate and stop which have a couple of underscores, such as __foo__ :
#Persisting renaming choices
Cutting-edge use of the home mangling ability concerns storage space the latest mapping off brand new name in order to mangled label within the a persistent cache. Whenever let, all mangled assets renamings is recorded regarding the cache when you look at the very first generate. After that builds reuse the newest renamings kept in new cache and you will incorporate more renamings for all the recently-extra characteristics. It offers a number of consequences:
The fresh cache serves as a listing of all services that have been mangled. Possible examine they to see if you can find one unforeseen assets renamings.
You might eliminate mangling to own private functions by form the newest rebranded value so you’re able to false instead of to help you a string. This will be just like the set aside props form but with the a great per-assets foundation.
You can guarantee consistent renaming ranging from yields (elizabeth.g. a central-thread document and a web site worker, otherwise a library and a plug-in). Rather than this particular feature, for each and every build should do a different renaming procedure as well as the mangled possessions names likely would not be consistent.
Whenever we require customRenaming_ is rebranded to help you cR_ and then we wouldn’t like disabledRenaming_ to-be rebranded at all, we can violation another mangle cache JSON to esbuild:
This option tells esbuild to help make particular metadata concerning build during the JSON structure. Next example places new metadata inside a file called meta.json :
This data may then getting assessed of the other devices. Such as, plan friend normally eat esbuild’s metadata structure and you may creates a treemap visualization of your modules on your plan and exactly how far space each of them occupies.