-
-
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
Babel polyfill documentation for Webpack is wrong resulting in all polyfills being compiled into bundle #7254
Comments
Hey @kroko! 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 |
Reference to the original webpack-loader ticket babel/babel-loader#567 |
- per babel/babel#7254 - like in the bug report, it was including _all_ polyfills - per the docs, 'usage' works roughly similarly to 'entry' because "a bundler will load the same polyfill only once" - still need core-js installed to install polyfills for libraries that require it - i.e. isomorphic-fetch requires a Promise polyfill - Babel can't detect that it needs it because Babel isn't parsing imported libraries
- per babel/babel#7254 - like in the bug report, it was including _all_ polyfills - per the docs, 'usage' works roughly similarly to 'entry' because "a bundler will load the same polyfill only once" - still need core-js installed to install polyfills for libraries that require it - i.e. isomorphic-fetch requires a Promise polyfill - Babel can't detect that it needs it because Babel isn't parsing imported libraries - improve comments of the polyfills file
Related to babel/babel#7254
Doc changes landed in babel/website#1858! |
Bug report
Bug in Babel polyfill documentation for webpack
Input Code
Repo
Revelation posted in babel-loader
Babel/Babylon Configuration (.babelrc, package.json, cli command)
.babelrc
.browserslistrc
or
webpack.config.js
Expected Behavior
When '@babel/polyfill' is included in webpack entry point as per documentation and
"useBuiltIns": "usage"
is used then then all polyfills are stripped and only ones found by union of usage within the code and specified browserlist are left.When '@babel/polyfill' is included in webpack entry point as per documentation and
"useBuiltIns": "entry"
is used then then all polyfills are stripped and only ones found by specified browserslist are left.Current Behavior
When '@babel/polyfill' is included in webpack entry point as per documentation and
"useBuiltIns": "usage"
is used then then all polyfills will be included as well as ones found by usage and browserlist combo resulting in monstrous bundle.When '@babel/polyfill' is included in webpack entry point as per documentation and
"useBuiltIns": "entry"
is used then then @babel/polyfill is not found, which effectively means that babel cannot strip unneeded, thus all polyfills will be included in the bundle resulting in monstrous bundle.Possible Solution
Make changes in Polyfill documentation as well as in babel-preset-env documentation
The current statement
is correct only in one of three possible
useBuiltIns
settings (so in 2 cases out of 3 users are building all polyfills into their bundle).They should state that:
"useBuiltIns": "usage"
then babel polyfill should not be included neither in source nor webpack entry (but it has to be installed of course). Browserslist configuration should be present."useBuiltIns": "entry"
then babel polyfill should be included in source, not webpack entry. Browserslist configuration should be present."useBuiltIns"
key or it is explicitly set to false"useBuiltIns": false
then babel polyfill should be included in webpack entry, but it can be included also in source (the latter being unadvised due to hoisting).Context
By trusting documentation I have deployed unnecessary large bundles although I have targeted new browsers.
I use .browserslistrc file as it is also used by PostCSS autoprefixer (JS and CSS features stay in sync).
Your Environment
The text was updated successfully, but these errors were encountered: