fix(bundles): Use ESM tslib build for the browser bundles #397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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
andbrowser.js
bundles, because newer esbuild versions keep all of the jsdoc comments 😔. Thebrowser.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.