evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.98k stars 1.14k forks source link

How to work with core-js ? #3803

Closed vaynevayne closed 3 months ago

vaynevayne commented 3 months ago

I know ESBUILD doesn't add any polyfill, but I was wondering how to configure useage injection for core-js in an esbuild project? For example, I use Vite

evanw commented 3 months ago

Sorry, I don't know anything about core-js. I did a web search for you and found this:

Note that by default, Vite only handles syntax transforms and does not cover polyfills. You can check out Polyfill.io which is a service that automatically generates polyfill bundles based on the user's browser UserAgent string.

You could consider asking Vite and/or core-js for additional information if needed.

vaynevayne commented 3 months ago

Are You Ai?

evanw commented 3 months ago

What? No. In any case, I'm closing this issue as this isn't a bug with esbuild.

evanw commented 3 months ago

It doesn't look like esbuild tree-shakes this. Running echo 'import "core-js"; [].at(-1)' | esbuild --bundle gives 900kb of output for me. If you have a case where esbuild's bundler is tree-shaking something incorrectly, then you'd need to provide specific reproduction instructions for me to be able to fix the bug with esbuild.

Note that this is the esbuild repo, not the Vite repo. It's possible that Vite's bundler is doing something different that what esbuild's bundler does. As far as I know Vite uses Rollup for bundling, not esbuild, and also layers a lot of custom stuff on top. If you have a Vite-specific question then you should ask on the Vite repo instead: https://github.com/vitejs/vite.

zloirock commented 3 months ago

It doesn't look like esbuild tree-shakes this. Running echo 'import "core-js"; [].at(-1)' | esbuild --bundle gives 900kb of output for me.

Polyfills optimization / injection requires some specific logic like it's implemented in SWC or Babel. Since esbuild also transforms new syntax features, it could be good to have the same for the standard library features (polyfills optimization / injection) to avoid extra tooling in the development stack.

In case if you are interested in implementing this, I can open an issue and consult about it.