-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Document the extent of ES6 polyfilling #969
Comments
Hi @jhorneman , let's keep track here #531 |
Thanks. Sorry, I only looked through the docs issues, not the pull requests. I'll do that next time! |
It's not meant to be used as a dependency, it's a polyfill. So you should not try to import it. It just makes sure you have a global Wrong: import fetch from 'whatwg-fetch'
fetch() Right: fetch() I agree we should document available polyfills. |
People commonly mistakingly assume Create React App polyfills ES6 runtime methods like |
What is the best practice to adding polyfills to CRA apps? For example: I want to polyfill Array.includes and I'm wondering where and how to add it and be consistent with the CRA worldview |
If you're okay with using CDNs, consider using https://polyfill.io/. Don't forget to add Promise, fetch and Object.assign to If you'd prefer to bundle them with your app, you can install |
Ahh Ahh thanks Dan, at the time instead of
|
@gaearon Should babel-preset-env take care of polyfilling only needed built-ins? |
ping @hzoo |
The way it works now it requires you to have
1 is not including polyfills based on the browsers, 2 is not including polyfills that aren't used in the codebase itself (would have to include node_modules/ 3rd party bundled code too if they expect the user to provide them). Seems to be a difficult thing to do so an open issue for it at babel/babel-preset-env#84 (most likely needs 2 passes?) |
@hzoo I'd say 1 pass is enough if you use aickin's approach and modify his plugin to not output imports if target set of browsers already supports them. |
The issue brought up at the end of #914 where this doesn't work well for people who use react-native-web and want to import some JS-only React-Native dependencies. This project already support this use case by aliasing |
The build times are already pretty slow. We won't be making them slower by compiling everything in |
By the way polyfills are now documented here: So we can close this. |
According to facebook/create-react-app#969 (comment): create-react-app already polyfills fetch
Assuming no major misunderstandings from my side: It was not clear me from the documentation that create-react-app installs fetch (whatwg-fetch), and that this is then available to me in my own JavaScript code. I only found this out when I looked at create-react-app (CRA)'s package.json file and tried it out.
I assume the presence of fetch and its use in user code is intended, but I cannot assume this is true for everything inside CRA's package.json file.
It seems to me there are three kinds of dependencies inside create-react-app:
It is hard to tell right now which dependency is which. It would be great to have this documented somewhere. I would propose something, but I lack the requisite knowledge.
The text was updated successfully, but these errors were encountered: