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

Decrease browser bundle size #679

Open
mb21 opened this issue Mar 27, 2024 · 1 comment · May be fixed by #681
Open

Decrease browser bundle size #679

mb21 opened this issue Mar 27, 2024 · 1 comment · May be fixed by #681
Labels

Comments

@mb21
Copy link

mb21 commented Mar 27, 2024

Looking at the bundle files for lib.esm for example:

image

(this was generated in an Astro.js project with rollup-plugin-visualizer).

I was especially curious why lib.esm/browser/fileReader.js is so big even though the source file is only a few lines. Running yarn run build-transpile-esm results in a 14kb file. The problem is that babel includes all the following functions:

_typeof
_regeneratorRuntim
asyncGeneratorStep
_asyncToGenerator
_classCallCheck
_defineProperties
_createClass
_toPropertyKey
_toPrimitive

Most of which is not needed for more or less modern browsers anymore.

I'm not an expert in babel and npm package bundling, but AFAIK it's nowadays best practice for a JS library to kinda just ship the source, so that the bundler in the project that consumes the library can optimize for the browsers they want to support and tree-shake away the functions not used?

@mb21 mb21 added the question label Mar 27, 2024
@mb21 mb21 linked a pull request Apr 11, 2024 that will close this issue
@Acconut
Copy link
Member

Acconut commented Apr 17, 2024

Thank you for looking into this!

I'm not an expert in babel and npm package bundling, but AFAIK it's nowadays best practice for a JS library to kinda just ship the source, so that the bundler in the project that consumes the library can optimize for the browsers they want to support and tree-shake away the functions not used?

I agree, we should get rid of the polyfill for async/await and generators. We can assume support for those features in the tooling by now.

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

Successfully merging a pull request may close this issue.

2 participants