-
-
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
Using @babel/runtime-corejs2 and @babel/runtime-corejs3 leads to larger bundle sizes #9853
Comments
Hey @GeorgeTaveras1231! 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 |
At least, you should not use together However, it's not the main reason for increasing the size of the bundle. |
@zloirock I understand that |
In your example, without |
@zloirock I'm experiencing something related to this and I'm not seeing a clear explanation here. With Other vendor bundles have a similar 10-20kb size increase as well. Sure it's not a huge difference, but I thought the I should mention that in all three scenarios my app works fine in the older browsers I've specified, so it's not an issue of polyfills not being included in some of the builds. |
What are your preset-env targets? |
|
@zloirock What do you mean by I'm not following why is that the case? As I see it as per the docs from
So the size of the bundle above is smaller because the polyfillable APIs have not been provied by the user. When we specifiy the corejs version it will be done automatically by us. But how does this relate to |
Yep. They are for the same - injection polyfills on usage, but do it in different ways - |
Are you saying we shouldn't be using I'm still experimenting with different combinations and keep getting different bundle sizes, so I'm trying to figure out what exactly is the best config (assuming there aren't bugs causing increased bundle size in certain situations). I did come across RFC #10008 which seems very interesting. In my particular case here I'm OK with global pollution if it means lower bundle size as this is an app, not a library. After getting some clarification I'll report back with my bundle sizes under the different configurations. |
@dlong500 only Global polyfills could be larger, but they are more correct. |
Sorry for being dense. Can you clarify what you mean above? Am I missing some documentation that exists on using And finally, what would be your general recommendation at this point for what options use for an application (not library) being bundled with webpack. |
|
Remove "useBuiltIns" as it is not required anymore. babel/babel#9853
Sorry... What? |
I will try to clarify in details about what happens exactly and why. First, Now, what does
The 'usage' word suggests what Ok, now let's see what
As we can see, the imports come from Answer to the question:
As explained above, your app code is bundled together with the polyfills for features like Answer to the question:
As explained above, with this config, polyfills are included from the Answer to the question:
The answer is NO. This is not obvious at first. The only case where you will get away with this usage is when you include
The transpiled code is this:
Look at this line here:
Answer to the question:
I'll go like this: App: If you are authoring an app, use Library: If you are authoring a library, use only This is my understanding, @zloirock , @nicolo-ribaudo feel free to correct me if I am wrong somewhere. Also feel free to ask if something is unclear from the explanations. Useful links: #10008 Thanks for reading! |
@JMarkoski Thank you very much for this. My understanding of how babel and core-js work is much clear now. Here is another comment around the same topic #9728 PS: Also your issue links are wrong. |
Oh, I messed up the links. They are fixed now. PS: You are welcome, I'm glad if it helped. |
@JMarkoski Thank you for your explanation! !
I try to set this option to
I don't think this library can be used on other environments. EDIT: There is an example using |
@JMarkoski that is a fantastic rundown; is there an equivalent somewhere in the docs that I'm missing? It's really unclear how these options interoperate and what the correct approach should be. |
I'm sorry for responding late guys. @elyobo Thanks, I'm glad if my answer helped. I'm not aware of such explanation in the docs/issues, my understanding comes from reading the source code of babel/core-js and trying different configurations and seeing how they behave. I was motivated to write on the topic exactly because there wasn't any explanation I could find anywhere on how exactly the options work together and what happens exactly and why. The docs explain them but you don't get the full idea of how the options play together. It would be nice if we add detailed explanations in order to clarify their usage, because I've seen improper usage of them in many projects/tutorials, which leads to not so easy to debug errors if you are not very familiar with how slightly different configs of the tools you use affect your code. |
This is very confusing stuff, but this conflicts with `useBuiltIns: 'usage' on preset-env, which already imports (global-polluting) core-js polyfills based on their usage *and* our target browsers. Whereas plugin-transform-runtime inserts "pure" (non-global-polluting) polyfills but does *not* care about our target browsers (it inserts them for everything). This has the effect that we were importing core-js polyfills twice: once for the global versions inserted by preset-env based on usage, and once for the pure versions from plugin-transform-runtime. More details can be found in this helpful comment by Jovica Markoski: babel/babel#9853 (comment) However, I didn't follow his suggestion to use `useBuiltIns: 'entry'` with a single core-js import at the top, because while this does only import polyfills needed by our target browsers, it doesn't do that based on /usage/. It imports any polyfill potentially needed by our supported browsers, which includes a ton we don't use and bloats the build size. So I'm still using the 'usage' setting here, but I've added @babel/runtime to the babel-ignored exceptions list so that the helper utilities receive polyfills too. React is also added as an exception to the babel-ignored list, because the "react" and "react-dom" libraries must share the same Symbol polyfill to avoid issues like facebook/react#8379.
@JMarkoski your comment above is excellent. the division on "making an app? a library?" is what kinda just makes it Obvious, the solution. i'm sure in hindsight i could read the relevant docs again, and possibly make sense of it myself... tho i'm not 100% sure ;) thanks for the speedy understanding mostly made this a comment to say: really might be worth clarifying this confusion in yet Another way in babel docs, because i think many people will go down a searching-hole for this |
@JMarkoski holy crap, thank you for that excellent explanation!! 👏🏻 I had spent the last 2 days banging my head against the wall trying to understand how all this ties together - your comment made everything so much more clear! |
This is in order to actually let `useBuiltIns: 'usage'` make its work regarding browserslist – with Babel runtime we actually import all polyfills anyway. babel/babel#9853 Interesting comment: babel/babel#9853 (comment)
To resolve the problem, which is also mentioned there:
You can also include {
test: /\.jsx?$/,
exclude: {
and: [/node_modules/],
not: [
/@babel[\\/]runtime/, // <---- include it by not exclude it.
],
},
use: {
loader: 'babel-loader',
options: {
// omitted.
}
}
} Now But here is a caveat: Say |
Bug Report
Current Behavior
When configuring
@babel/plugin-transform-runtime
to usecorejs2
orcorejs3
, bundle sizes increase x7 (corejs2) and x11 (corejs3)Input Code
Expected behavior/code
I expect that the bundle sizes stay relatively close, when switching from
@babel/runtime
to@babel/runtime-corejs2
or@babel/runtime-corejs3
Babel Configuration (.babelrc, package.json, cli command)
Configs to use
@babel/runtime
Configs to use
@babel/runtime-corejs2
Configs to use
@babel/runtime-corejs3
Environment
Possible Solution
N/A
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
Repro repo: https://github.com/GeorgeTaveras1231/corejs-size-regression-repro
Snapshot:
The text was updated successfully, but these errors were encountered: