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

(Question)Is there a way to share code between app and libs? #833

Open
NE-SmallTown opened this issue Jun 1, 2020 · 4 comments
Open

(Question)Is there a way to share code between app and libs? #833

NE-SmallTown opened this issue Jun 1, 2020 · 4 comments
Milestone

Comments

@NE-SmallTown
Copy link

NE-SmallTown commented Jun 1, 2020

core-js/modules/es.promise.js and core-js-pure/modules/es.promise.js are exactly the same code, the main difference is just 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 the global?

IMO, this will greatly reduce the duplications because at now many libs usally use @babel/transform-runtime with { corejs: 3}(finally is core-js-pure) but many apps use preset-env with {corejs: 2} (finally is core-js), there is no shared/shareable codes between apps and libs, right?

Refer to babel/babel#11515

@NE-SmallTown
Copy link
Author

@slowcheetah @zloirock Hi, would you mind take a look at this? Thanks~

@zloirock
Copy link
Owner

It's a good issue.

core-js/modules/es.promise.js and core-js-pure/modules/es.promise.js are exactly the same code

They rely on modules with the same name, but with a different code.

Could we import the "pure" implementation and set it to global for global polyfill?

The "pure" implementation has too many limitations, uses expensive workarounds, in many cases non-complete, so we could not do it.

I played with solving this problem for a long time. Sharing common modules between those versions makes no sense - it's just a little part of the code size and it will increase the size of each version if it's used alone.

However, now I have an idea of how to solve this issue in the next generation of tools. The details will be later.

@NE-SmallTown
Copy link
Author

Ah, happy to wait for your 'The details'

@zloirock
Copy link
Owner

zloirock commented Feb 14, 2023

I wanted to publish details a long time ago, but I posted this only right now. This problem should be solved in this, transpiler-based, way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants