developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.03k stars 362 forks source link

How to target browsers with es6 support? #942

Open torotil opened 2 years ago

torotil commented 2 years ago

I’ve looked at browser support for ES6 + async/await for our sites and as it looks transpiling to ES5 might not be worth it. It makes less than 1% difference in browser coverage. As a test I tried to find a browserslist config that allows this.

So far I’ve tried:

Is there a way to use microbundle to bundle and minify JS and still have ES6 output?

rschristian commented 2 years ago

I’ve looked at browser support for ES6 + async/await

What's your intended target? ES6 or ES2017? async/await is an ES2017 feature, not ES6/ES2015.

If you want ES2017, that's our modern output, see: https://github.com/developit/microbundle#-modern-mode-

No config needed, it's one of the default outputs.

torotil commented 2 years ago

Ah nice! There is still the problem that I can either import regenerator-runtime or not. If I do it’s also included in the modern output. Can I avoid that somehow?

rschristian commented 2 years ago

Why do you need regenerator?

Edit: If the issue is that the built code is referring to it, you likely still have a babel or browserslist config that's getting picked up and caused unwanted transforms.

torotil commented 2 years ago

The code is using both async/await as well as generator functions (yield *).

Ah, I see. The problem only arises because I wanted both the .js and the .modern.js output to be usable. My idea was to have both ready and decide on a case by case basis which to use. If I ignore the .js output then I can simply not import regenerator-runtime and have a .modern.js without it.