-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
"useBuiltIns: usage" for node_modules without transpiling #9419
Comments
Hey @fabb! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
I ran into this today. Due to #8932, the work around for this seems to be using any needed features in the main script to trigger usage detection. export async function _polyfillPromise() {} |
Let me link this issue to my discussion: #14433 |
You can now compile your |
Feature Request
The Problem
"useBuiltIns: usage" of preset-env is a genius idea to only include the polyfills really needed. Unfortunately it does not work for node_modules. We could whitelist node_modules to be babel transpiled so polyfills get inserted for these as well, but this might not be desired for several reasons:
Proposed Solution
preset-env could get a new option to follow node_module imports in transpiled files, and analyze the imported file for polyfills needed, and insert necessary polyfill
import
s into the originally transpiled file. It might be that a new webpack-specific plugin would be needed to understand and followimport
s.In
a.js
node_modules/somemodule/index.js
Out
a.js
node_modules/somemodule/index.js does not get modified.
Of course some cache will be needed to not analyze the same node_modules over and over again, maybe coupled to the version in package-lock.json, and only disabled for
npm link
ed modules.Alternatives Considered
useBuiltIns: usage
is able to)Teachability, Documentation, Adoption, Migration Strategy
Since it is a purely additive feature, users can gradually opt in and replace their old polyfilling strategy with this one. The new option could be called
useBuiltIns: 'usage-node_modules'
or similar.The text was updated successfully, but these errors were encountered: