preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.56k stars 1.94k forks source link

preact/compat tree shakability #3295

Open samouri opened 2 years ago

samouri commented 2 years ago

summary

I noticed that when importing from preact/compat, much more is pulled in than expected. For example, when bundling code like this:

import { forwardRef } from 'preact/compat';

It creates ~2x greater binary size than directly copy/pasting the necessary function.

I've created a minimal reproduction here: https://github.com/samouri/preact-shakability

senpro-ingwersenk commented 3 weeks ago

Originally posted in 2021, still open and apparently still a problem?

Is someone working on this?

rschristian commented 3 weeks ago

As the "after X" tag indicates, it's something we probably can't safely change in Preact X.

It's something we'd like to address in the future, at least in part (some of compat will always be unshakable in all likelihood), but there's nothing anyone can change about this now.