-
-
Notifications
You must be signed in to change notification settings - Fork 158
Discussion: useBuiltIns (usage only, not "entry" point method) #284
Comments
This issue has been automatically marked as |
i like the idea of creating a polyfill registry. If we can:
i think (1) is static analysis i guess, can always write integration tests and run it on saucelabs or browserstack to identify broken code :-) |
This is bound to happen given how dynamic JS can be, but being smart about how to tell babel not to use a polyfill when not needed becomes a priority. One option is to tell babel to Since this would be a file-by-file issue, I would propose some sort of comment-disabling system, similar to eslint's
Yes! These, as far as my experience has been, are always pre-transpiled for wide support, and only sometimes provide a special, es6 version for folks who don't care about support. I would agree that babel (and the project dev) should only care about polyfills that would apply to the current application code and ignore third party libs. It has an ancillary benefit of saving on processing/speed as well.
I'm not sure this would solve the previous issue of babel being unable to figure out the type of a variable. I think any of the suggestions similar to this will also hit the same problem. I would still advocate for a better exclusion strategy than the complexity of how babel would be able to figure out types for the countless use cases in code. |
I had a somehow unrelated question for |
@tomchentw It's not only preferred with |
This issue has been moved to babel/babel#6626. |
Problem
How can we import the minimal amount of polyfills required for an app?
import 'babel-polyfill'
is wasteful: you may not use a certain built-in in your code and your supported environment may already natively support it.After #241, we now have an option (in 2.0-alpha) that will individually add only the used polyfills at the top of each file.
Instance/Prototype Methods (not solved, but it's fine)
The way we handle this is to be conservative and be ok with some false positives because it would still be less than importing the whole polyfill. In the future we could be smarter about knowing whether a variable is a string/array or not via inferring types or with type annotations from TS/FLow.
node_modules
/Third party librariesFigure out a way to determine the polyfills required for a library programmatically
package.json specify polyfills usage
crazy: Create a database/registry similar to https://github.com/DefinitelyTyped/DefinitelyTyped or compat-table but around polyfill/syntax usage. This can be automated by just running the Babel plugin over each library to determine the array of polyfills required (don't need manual PRs). Then babel-preset-env can use this information to import the correct polyfill automatically.
For React: https://unpkg.com/[email protected]/
Run the "use-built-ins-plugin" which runs over all of React to find the usage of a polyfill and instead of overwriting the file, we modify the plugin to just return a list of potential polyfills.
Add this information to some db for each library version
When preset-env encounters a require/import of React, we check the package.json to know the version used and then import the correct polyfill before the library is loaded.
The text was updated successfully, but these errors were encountered: