kyt icon indicating copy to clipboard operation
kyt copied to clipboard

Explore babel-preset-env

Open tizmagik opened this issue 9 years ago • 4 comments

With #255 we now have babel-polyfill in place both on the client and server for necessary ES6+ support. In the case of the client, relatively modern browsers don't need the entire polyfill, and for the server since node 6 is already a pre-req for kyt, most of the polyfill is also unnecessary there.

Although it's arguably still early for babel-preset-env, I think it might be good to experiment with it and see if we can use it to polyfill only what's necessary for newer browsers in the client bundle and node 6+ in the server bundle.

tizmagik avatar Nov 01 '16 03:11 tizmagik

I can't get a good read on babel-preset-env. Does it actually include polyfills or is it for transformation only? If it's the latter, I don't think it would be a replacement for babel-polyfill.

delambo avatar Nov 01 '16 12:11 delambo

No, unfortunately it's not a replacement for babel-polyfill, it just results in less code being transpiled and, presumably, a smaller overall bundle size.

However, something to only polyfill what's needed seems like it's in the cards for babel-preset-env, see this issue: https://github.com/babel/babel-preset-env/issues/20

With that being said, on the server-side we might be able to get away with only polyfilling what's missing (e.g. generator functions, etc) and leave off the rest since node 6 has pretty decent ES6 coverage and it's a more predictable environment. We wouldn't be able to leave off the polyfill for the browser, however.

tizmagik avatar Nov 01 '16 13:11 tizmagik

Babel itself only transforms syntax so the preset just determines the least common denominator of plugins to run on the browsers/environments you specify in the options. Instead of changing your set of plugins yourself (turning off plugins over time) it should calculate that for you.

hzoo avatar Nov 01 '16 17:11 hzoo

I'm working on the polyfill part in https://github.com/babel/babel-preset-env/pull/56

hzoo avatar Dec 07 '16 16:12 hzoo