-
Notifications
You must be signed in to change notification settings - Fork 107
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
Implement babel-loader in webpack (with polyfill) #379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks for the contrib. I'm curious if there's something we could add to our web tests to ensure that this doesn't regress.
@@ -73,5 +76,7 @@ | |||
"hystrix", | |||
"rate-limiting" | |||
], | |||
"dependencies": {} | |||
"dependencies": { | |||
"core-js": "^3.3.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a devDependency
shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! More info:
https://babeljs.io/blog/2019/03/19/7.4.0
The core-js package is a light suite of polyfills for all the major new JS features. With babel useBuiltIns
, it will dynamically add the imports for any core-js polyfills to the dist folder. These polyfills will bloat the distribution a tiny bit, but this package will be able to serve a much wider audience as a result. If you prefer to leave the polyfills out, you can remove coreJS and just use babel preset-env, with no args, to transpile only the syntactic sugar, without adding any polyfills. Given that this package is marketed for browsers, I think the overhead is worth it.
Note there's also a second regenerator-runtime
polyfill dependency that Babel can generate imports for. I didn't include it as a dependency in this PR because you don't use generators or async/await code. If you would prefer maintaining async/await code, then you can easily add the regenerator-runtime
dependency and a single require("regenerator-runtime/runtime");
in your entrypoint (like described in the babel blog). This will transpile your bleeding edge ES2019 into browser-native ES5 at build time.
For regression testing, I guess you could do something with Selenium/IE11, BrowserStack, etc. Another possibility would be piping the output through the Webpack UglifyJS plugin, which only supports ES5 bundles. This would give you an added benefit of shrinking your dist size. But then you need to test that the Uglified output works too... :) |
What actually needs a polyfill? My view is that libraries shouldn’t do any polyfilling and instead leave it up to the developer. Polyfills are modifying globals which is generally a bad idea. Imagine an app becomes dependant on a polyfill in here for example without realising, and then they make a change to lazy load opossum. There’s the risk of their app breaking depending on when the polyfill gets loaded in, which could also be difficult to debug. So my preference would be no polyfill and a note about required polyfills and maybe some example code to add them, or even better rewrite the logic that needs a polyfill to no longer need one (if feasible) |
Is there something that needs a polyfil specifically? I think we tried really hard to make this library have no dependencies, so it would be a bummer if we added a dependency to it just for 1 thing |
Added an alternative PR with no polyfill: #380 The polyfills installed by babel/core-js are:
It's a huge list because no browserlist was defined. If you put bigger limits on the browsers you target, you get far fewer polyfills. You can compare the differences between the I agree that since you already have no deps, it should probably stay as lean as possible. |
Closed for #380 |
Fixes #371
Uses core-js v3 polyfills