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

Support tree-shaking #602

Merged
merged 1 commit into from
Jun 15, 2021
Merged

Conversation

TheRusskiy
Copy link
Contributor

Support tree-shaking by enabling preserveModules

In order to enable tree-shaking, we need to specify sideEffects: true,
unfortunately, after experiments, it turned out not to be enough and I had to enable preserveModules, which webpack seems to be able to use to properly remove unused code, that part was Inspired by jaredpalmer/tsdx#276

I first noticed that headless-ui is not being tree-shaked in lighthouse:
Screenshot 2021-06-09 at 00 20 42

After adding the changes in this PR the packages is no longer showing up as unused:
Screenshot 2021-06-09 at 00 20 59

I also ran @next/bundle-analyzer
Before:
Screenshot 2021-06-09 at 00 06 42

After:
Screenshot 2021-06-09 at 00 07 25

Also, before / after results from Chrome:
Screenshot 2021-06-09 at 00 26 52
Screenshot 2021-06-09 at 00 27 12

@vercel
Copy link

vercel bot commented Jun 8, 2021

@TheRusskiy is attempting to deploy a commit to the Tailwind Labs Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

headlessui-react – ./packages/@headlessui-react

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/AZyErYzMxkdzJhEgUwnGCWdUAAga
✅ Preview: https://headlessui-react-git-fork-therusskiy-tree-shaking-tailwindlabs.vercel.app

@rozenmd
Copy link

rozenmd commented Jun 12, 2021

This looks awesome - I was just looking at headlessui and trying to work out why importing a single <Transition> component would cost 50KiB in bundle size.

@TheRusskiy
Copy link
Contributor Author

TheRusskiy commented Jun 14, 2021

@rozenmd until this is fixed, if you want to, you could use
https://www.npmjs.com/package/headlessui-react-shake
it's this PR published to NPM
version 1.2.0

@RobinMalfait
Copy link
Member

Hey! Thank you for your PR!
Much appreciated! 🙏

I've been looking at treeshaking, by moving to esbuild and bumping typescript. This is not 100% straight forward because esbuild doesn't support UMD last time I checked and a few other quircks.

Thank you for doing this!

@RobinMalfait RobinMalfait merged commit abe3e1b into tailwindlabs:develop Jun 15, 2021
@RobinMalfait RobinMalfait mentioned this pull request Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants