preset-modules icon indicating copy to clipboard operation
preset-modules copied to clipboard

Proper usage with selective polyfilling?

Open jquense opened this issue 6 years ago • 9 comments

Is there a good, or preferable setup using preset-modules, along with `preset-env' auto polyfilling? Perhaps all the transforms disabled so the polyfills are also included?

jquense avatar Dec 20 '19 15:12 jquense

We will move this preset into preset-env soon (either in the next Babel minor release or in the one after), so it will be enough to use @babel/preset-env with the esmodules: true option.

nicolo-ribaudo avatar Dec 20 '19 16:12 nicolo-ribaudo

Right - I believe even with all transforms enabled right now preset-env would produce polyfill imports since it isn't aware preset-modules is transforming things. I believe the useBuiltIns:entry option should work in tandem, though.

developit avatar Jan 07 '20 22:01 developit

At the moment i've got them working together but have had to manually exclude any transforms in preset-env. On a tangent it'd be nice to have a leaner polyfill option as well, corejs is thorough, maybe too much so :P

jquense avatar Jan 08 '20 03:01 jquense

@jquense I couldn't agree more! :)

FWIW I've found myself using polyfill.io's configurator tool and then grabbing the resulting polyfills (with the ?flags=always parameter) and just inlining that. I tend to conditionally load it using <script nomodule>.

BTW if you have a working exclude list handy I would love to take a peek. It might be worth dropping it in this issue so we can pin it for folks wondering the same as you were.

developit avatar Jan 09 '20 16:01 developit

its luckily as easy as using a regex since the babel plugins are consistently named https://github.com/4Catalyzer/javascript/blob/esm/packages/babel-preset/esm.js#L25

jquense avatar Jan 09 '20 16:01 jquense

oh, brilliant haha. One thing potentially worth trying would be to exclude known false positive inclusions of corejs:

exclude: [
  /transform/,
  'es.map',
  'es.set',
  'es.object.assign'
]

developit avatar Jan 10 '20 19:01 developit

We will move this preset into preset-env soon (either in the next Babel minor release or in the one after), so it will be enough to use @babel/preset-env with the esmodules: true option.

Babel 8 is planned to be released in March. Any chance it will be included then? :)

ba55ie avatar Feb 06 '20 11:02 ba55ie

It will! And in case we release 7.9.0 before 8.0.0, it will be already included in 7.9.0.

You can turn on notifications for https://github.com/babel/babel/pull/11083 :wink:

nicolo-ribaudo avatar Feb 06 '20 11:02 nicolo-ribaudo

I don't know where to post this, but the Safari 10 polyfill for supporting "nomodule", is this part of this plugin, or do we still need to include that ourselves?

BregtDeLange avatar Mar 17 '20 17:03 BregtDeLange