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

Transpile lib to more modern JS #126

Closed
dcastil opened this issue Aug 13, 2022 · 9 comments · Fixed by #287
Closed

Transpile lib to more modern JS #126

dcastil opened this issue Aug 13, 2022 · 9 comments · Fixed by #287
Labels
breaking Is breaking change context-v2 Related to tailwind-merge v2 feature request
Milestone

Comments

@dcastil
Copy link
Owner

dcastil commented Aug 13, 2022

Note
If you are affected by this, please let me know in a comment.

Currently the library is transpiled with the default browserslist config which means it is transpiled to ES5.

I played around with some more modern configs like last 3 years and > 0.1%, maintained node versions and could reduce the minified library size by 1 kB and the gzipped size by 0.5 kB. Additionally, I expect some minor performance improvements because e.g. rest/spread isn't polyfilled anymore.

Transpiling to more modern JS could be a breaking change for some users of tailwind-merge, so this would need to go into a v2 release of tailwind-merge.

I could also provide an additional legacy build (import { twMerge } from 'tailwind-merge/legacy') which stays transpiled to ES5 since everything in tailwind-merge can be polyfilled. But I guess that's not necessary since devs who need to support ES5 probably transpile their dependencies these days anyway.

@dcastil dcastil changed the title Transpile lib to modern JS Transpile lib to more modern JS Aug 13, 2022
@dcastil dcastil added this to the v2 milestone Aug 13, 2022
@dcastil
Copy link
Owner Author

dcastil commented Aug 20, 2022

Related: #132

@dcastil dcastil added the breaking Is breaking change label Feb 4, 2023
@jzxhuang
Copy link

Just showing some support for this — any efforts to lower the bundle size is much appreciated! 22kB minified is a pretty big bundle for this simple (but necessary) utility

@dcastil
Copy link
Owner Author

dcastil commented Apr 13, 2023

Thanks @jzxhuang!

I'm also looking for more opportunities to reduce the bundle size. The default config has by far the biggest impact on bundle size (75% of gzipped lib), so the biggest improvement could be to create that automatically based on the Tailwind classes actually used in the codebase. I have an open discussion about this in the Tailwind repo. But so far no movement there.

@yuuk
Copy link

yuuk commented Aug 14, 2023

I found that optional chaining not transformed to es5, so it cannot support chrome version less than 80

e?.substring(0,e.indexOf(":")

@dcastil
Copy link
Owner Author

dcastil commented Aug 14, 2023

@yuuk True, I see it as well. Is this causing an issue for you?

Note to myself:

@yuuk
Copy link

yuuk commented Aug 15, 2023

@yuuk True, I see it as well. Is this causing an issue for you?

Note to myself:

Yes, Some app's build-in browser may use low version Chrome core, like Alipay、WhatsApp, The problem I have encountered is that I open my project in Alipay Android build-in browser it causing an error.

@dcastil dcastil mentioned this issue Aug 15, 2023
@dcastil
Copy link
Owner Author

dcastil commented Aug 15, 2023

@yuuk I added a new issue to add an ES5-compatible build to tailwind-merge: #283

I will probably be able to ship it next weekend or so.

@dcastil
Copy link
Owner Author

dcastil commented Aug 16, 2023

Wrote down some thoughts on how to improve bundling in #283 (comment) which I could do as part of this as well.

dcastil added a commit that referenced this issue Aug 19, 2023
Targets should only be modernized in // To be enabled in #126
@github-actions
Copy link

This was addressed in release v2.0.0.

@dcastil dcastil added the context-v2 Related to tailwind-merge v2 label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Is breaking change context-v2 Related to tailwind-merge v2 feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants