📜 ⬆️ ⬇️

Breaking is not building. Or devolution

Recently, a couple of interesting articles appeared on Habré. The first was devoted to the problem of minimizing ES6 , the second about general helpful tips optimization webpack .

Everything would be fine, but both of them avoided the question of splitting the bundles into ES6 and ES5 for the purposes of minification and other optimization. And in general, while some people write and write articles about it - others (almost all) ignore this technique.

Because long. Expensive. And not so very much.
')
And you need to quickly, cheaply, and downward. Perhaps you should just reverse the evolution.



Idea


Describing an “idea” is not a good idea. It is better to describe how it should work. How the bundle formation process should work:


The development browser is here - so that async / await, generator, classes, arrow functions and so on. In general, target: esmodules in Babel.
I do not know about you, but I like this idea. That's just the old browsers that are still among us, this idea is not so that comes. (and therefore we all sizzle es5 in production, spiced with half a megabyte of polyfiles)

And that is what needs to be fixed.

Devolution


Devolution is a small cli utility that will take your bundle compiled into target: esmodules and degrade it to es5, adding all the necessary polyfiles along the way.

In short, then:


I ran the code on three projects of different levels of complexity:


The bonus from ESM bundle turned out to be a bit strange:


Again:


Simply. Quickly. Just stupid. We de-modernized the bundle. Old browsers! Ay - eat filed.

Well, new browsers will get a bundle with almost no polyfiles, no horrible transformations of generators and async / await, with arrow functions without tambourines (and they are generally faster). In general, everyone is happy, as it was originally intended.

github.com/thekashey/devolution
PS: In fact, at the moment devolution does not use swc , as it sometimes makes the code not very working - github.com/swc-project/swc/issues/280 , Babel is not so much slower - where the swc was being edited in 20 seconds, babel copes in a minute. With the time of “normal” assembly - from 5 onwards - this is a big plus.
PS: If suddenly it became interesting why the devolution is a video here .

Source: https://habr.com/ru/post/441942/


All Articles