Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: feature detection & polyfilling on the client side, possible with babel-loader? #843

Open
rondonjon opened this issue Apr 27, 2020 · 0 comments

Comments

@rondonjon
Copy link

rondonjon commented Apr 27, 2020

It is a common practice now to run builds several times, at least once for "older" browsers and again for "modern" browsers, with different sets of polyfills. This is IMO not the right way or the right stage in the build/load process to hande feature detection and polyfilling. IMO it should happen entirely at runtime.

There seems to be no easy solution to do this with the common babel / babel-loader setup.

The reason is probably that the babel-loader generates code which "hard-wires" all polyfills with require().

Would it be possible to wrap these in feature tests and loading them only conditionally, with a mechanism like dynamic requires?

(I know, the Dynamic Imports might night to be polyfilled themselves and hence be the only exception to the general approach.)

I've looked at the customize option of the babel-loader but found no documentation on the actual customization options, and the behaviour that was implemented in the webpack example seems to receive ready-made code from babel inside result.code, whereas the result.ast (which might be easier to extend with the desired behavour) is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant