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

fix(bundles): Use ESM tslib build for the browser bundles #397

Merged
merged 1 commit into from
May 6, 2023

Conversation

absidue
Copy link
Collaborator

@absidue absidue commented May 6, 2023

tslib is weird. The esbuild version that YouTube.js uses, isn't able to automatically pick the correct tslib build to bundle into the browser bundles, so it uses the commonjs one, which isn't treeshakable. This makes it pick the correct one, reducing the size of the bundles:

Bundle Before After
browser.js 893.3kb 875.8kb
browser.min.js 479.6kb 471.7kb

More recent versions of esbuild added support for tslib's weirdness, however they now aggressively preserve comments while bundling (previously they only preserved webpack's magic comments), so that tools like vite can add magic comments without esbuild stripping them. Unfortunately that means that it blows up the sizes of the node.cjs and browser.js bundles, because newer esbuild versions keep all of the jsdoc comments 😔. The browser.min.js bundle isn't affected by that, as part of the mimification process is striping comments.
Doesn't look like there is a sensible way to disable that behaviour.

@LuanRT
Copy link
Owner

LuanRT commented May 6, 2023

Very strange behavior indeed. Thanks for the PR.

@LuanRT LuanRT merged commit 2673419 into LuanRT:main May 6, 2023
@absidue absidue deleted the tslib-bundling branch May 6, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants