-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Parcel build includes all Core-js polyfills, or none at all #3742
Comments
I don't think useBuiltins works in parcel 1 and we kind of don't recommend it in Parcel 2 either as it results in larger bundle sizes due to duplicate polyfills all over the place. Probably even better to just include everything as that wouldn't cause duplicates. |
So the workaround right now is to run Babel manually to derive which polyfills are needed, and then manually include those polyfills in the file so Parcel can bundle them? |
If you really wanna do all that work to save a small amount of data over the wire sure. I'd just include it all |
Please read this carefully: https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4 core-js has ~180KB of minified filesize, wich equals slightly more than 1.5s of processing time on an average mobile phone, which are added to the time to interactive. It might seem like a rather small amount of data, but it is a huge downer on load times. |
@Keyes I’m aware of the impacts this has on performance. Just kind of meant it’s probably not worth it although it highly depends on target audience. For a business app it probably does not matter. If you’re mainly targeting mobile every bit counts though as you pointed out. Eventually tooling should do all these tweaks automatically. We’re receiving a lot of help on this field for Parcel 2. Sent with GitHawk |
This is already resolved in the upcoming Parcel 2 and perhaps won’t be fixed in Parcel 1. |
A workaround is described in #3216 by modifying the babel config for an environment you're building for. This works with Parcel 1. Example:
{
"plugins": ["@babel/plugin-transform-object-assign"],
"env": {
"production": {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
],
}
}
} Parcel 1 will use this configuration and babel will add the needed polyfill imports for you. The The import in import 'core-js/stable' is only needed when you use Now if you run:
Babel will then add the following imports (and parcel the bundled modules): require("core-js/modules/es.array.from");
require("core-js/modules/es.array.includes");
require("core-js/modules/es.string.includes");
require("core-js/modules/es.string.iterator"); |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. |
🐛 bug report
When using .babelrc and specifying both
targets
anduseBuiltIns: 'usage'
I was expecting parcel to only include the core-js polyfills that were necessary to work with the targeted browsers. Instead all polyfills are including (making build size huge).Alternatively, if
import 'core-js/stable'
is removed, then no polyfills are included.🎛 Configuration (.babelrc, package.json, cli command)
package.json
.babelrc
index.js
index-alternative.js
index.html
🤔 Expected Behavior
I'm not exactly sure. I was expecting one of the index.js files to compile to a version where only the required polyfills was included, to polyfill the Array.prototype.From and Array.includes methods for IE 11:
😯 Current Behavior
When running
parcel build index.html
it outputs both js files:It's not clear from the documentation whether it's required to import core-js (I think it's not?) but if core-js isn't imported then the polyfills aren't included in the built script.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: