In particular, esbuild isn’t made to preserve the value of getting in touch with
The fresh JavaScript minification formula inside the esbuild always yields output that’s really close to the minified returns measurements of business-fundamental JavaScript minification tools. If you find yourself esbuild isn’t the max JavaScript minifier in every instances (and you can doesn’t try to be), they strives to create minified returns within this a few % of how big faithful minification units for the majority password, not forgetting to achieve this much faster than other units.
#Factors
You will want to probably along with lay the prospective choice whenever minification is let. Automagically esbuild utilizes modern JavaScript has actually and make your own code less. Eg, good === undefined || a great === null ? step one : an is likely to be minified in order to a ?? step 1 . If you don’t wanted esbuild for taking advantageous asset of progressive JavaScript provides when minifying wooplus sorun, you are able to an adult code address for example –target=es6 .
The type stay away from series \letter is substituted for an excellent newline profile when you look at the JavaScript layout literals. Sequence literals might also be turned into theme literals in the event the target supporting him or her whenever this manage lead to reduced yields. It is not a bug. Minification form you are requesting smaller productivity, while the eliminate sequence \n takes two bytes since newline profile requires you to definitely byte.
Automatically esbuild wouldn’t minify the fresh new names of the market leading-top declarations. For the reason that esbuild will not know very well what you might be starting to your yields. You happen to be injecting the minified password on center from various other code, in which particular case minifying most useful-height es was dangerous. Function an output style (or providing bundling, which picks a productivity style to you personally for individuals who haven’t set one) tells esbuild that returns will be work at within its very own extent, and therefore it’s upcoming safe in order to minify top-level parece.
Minification is not not harmful to one hundred% of all of the JavaScript code. This can be true to own esbuild as well as almost every other well-known JavaScript minifiers like terser. toString() into the a features. The reason for it is because in the event the the code into the most of the characteristics had to be preserved verbatim, minification perform barely do just about anything whatsoever and you can might be very nearly inadequate. But not, because of this JavaScript password depending on the brand new get back value of .toString() will most likely break when minified. Like, particular patterns regarding AngularJS construction break whenever password is minified because AngularJS spends .toString() to learn new dispute labels off properties. An excellent workaround is with direct annotations rather.
Automagically esbuild does not preserve the significance towards the form and you will class items. This is because extremely code will not believe in which property and using shorter brands is a vital proportions optimisation. Yet not, particular code does believe in property to have registration and you can binding objectives. If you wish to have confidence in it you need to permit the remain brands option.
Entry to specific JavaScript have normally disable many of esbuild’s optimizations and minification. Specifically, playing with head eval and you may/or even the having statement avoid esbuild from renaming identifiers so you’re able to shorter brands because these possess cause identifier binding to take place from the manage go out instead of collect go out. This is certainly almost always unintentional, and simply happens because people are unaware of exactly what head eval is and exactly why it is bad.
The fresh new minification formula when you look at the esbuild cannot yet manage advanced password optimizations. In particular, the following password optimizations is actually easy for JavaScript code however they are perhaps not done by esbuild (perhaps not an thorough checklist):
- Dead-code elimination within means bodies
- Setting inlining
- Cross-statement lingering propagation
- Object figure modeling
- Allocation sinking
- Strategy devirtualization
- Symbolic delivery