ok-computer icon indicating copy to clipboard operation
ok-computer copied to clipboard

Improve tree-shaking

Open richardscarrott opened this issue 1 year ago • 2 comments

Both rollup and webpack fail to efficiently tree-shake the codebase which, although very small, would be still be nice given it is side effect free.

I think it's related to curried functions being executed on import but also specifically seems to be related to newing up errors in and, or etc.

https://github.com/richardscarrott/ok-computer/pull/21

richardscarrott avatar Sep 15 '22 07:09 richardscarrott

https://dev.to/livechat/tree-shaking-for-javascript-library-authors-4lb0

richardscarrott avatar Sep 15 '22 08:09 richardscarrott

It seems introspectValidator is problematic because it does in fact have a side-effect (throws), however it's only relevant if the return value is used so prob a legit case for PURE annotation, however it's all so brittle I think it'd be better to have a test which bundles w/ rollup and asserts the output.

Also, might want to try: https://github.com/Andarist/babel-plugin-annotate-pure-calls

richardscarrott avatar Sep 15 '22 09:09 richardscarrott