Skip to content
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

Should we combine the transform-runtime and preset-env in an application? #11515

Closed
NE-SmallTown opened this issue May 4, 2020 · 4 comments
Closed
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@NE-SmallTown
Copy link

NE-SmallTown commented May 4, 2020

Question 1

I find that there are many unnecessary duplications in the (webpack) bundle (output)result, to be specific, they all are the helpers(like classCheck, objectSpread(due to the object-spread plugin).

So, I want to reduce the duplications. If it's a library, sure, I will use transform-runtime plugin(refer to runtime-corejs3) to do this. But now this is an application, so, what's the correct way to do this?

Therefor I'm getting confused because the transfrom-runtime plugin is recommended for library(and is for the whole reduction. i.e. core-js, regenerator and the helpers). But here I just want to reduce the helper duplications, not others duplications because that has been done by preset/env.

So here the question I want to ask/discuss is that is it necessary to reduce the helpers duplications in an application, if yes, and how?

Question 2

The other question is, core-js/modules/es.promise.js and core-js-pure/modules/es.promise.js are exactly the same code, the main difference just is that the former has global pollution? If so, why core-js doesn't use(directly import) core-js-pure to polyfill and then add it to global? IMO, this will greatly reduce the duplications because at now the libs use transform-runtime(finally core-js-pure) but apps use preset-env(finally core-js), there is no shared/shareable codes between apps and libs, right?

@babel-bot
Copy link
Collaborator

Hey @NE-SmallTown! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

The docs are confusing: @babel/transform-runtime's corejs option is recommended for applications, but it's not discouraged for libraries. We only want to discourage using any polyfill injecting method that is not @babel/transform-runtime's corejs option when creating libraries.

Also, we are currently reworking our methods to inject polyfill to unify them: #10008

If so, why core-js doesn't use(directly import) core-js-pure to polyfill and then add it to global?

This should be asked in the core-js repository 🤷

@JMarkoski
Copy link
Contributor

Answer to the first question: To reduce the helper duplication you should use the @babel/transform-runtime plugin together with the @babel/runtime dependency. The corejs option of the @babel/transform-runtime plugin should be set to false. This way the plugin will alias the helpers to the @babel/runtime dependency, and every helper will be included only once in the application, thus reducing the size. For more thorough answer, see here: #9853 (comment)

@NE-SmallTown
Copy link
Author

Thanks, it's more clear now!

The second question has beeen refered to zloirock/core-js#833

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants