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

Improve tree shaking? #4

Open
cmdcolin opened this issue Dec 18, 2024 · 3 comments
Open

Improve tree shaking? #4

cmdcolin opened this issue Dec 18, 2024 · 3 comments

Comments

@cmdcolin
Copy link

Hi there,

I was interested in using longfn to reduce bundle size a little bit compared with long.. I thought the 'pure function' way that longfn works might lend itself to tree shaking but the bundle was maybe not 'tree shaken'.

I probably obsess over bundle size too much but it is including the entirety of longfn (6kb minified) instead of just the functions imported. (for comparison long.js ~10kb minified)

A production build using vite with just longfn imported can show this

image

Screenshot above made using "yarn build" in the repro, then running server in dist, and running "npx bundle-wizard http://localhost:3000"...of course react the major culprit in bundle there

Repo here, very minimal https://github.com/cmdcolin/longfn-tree-shake-repro/blob/master/src/App.tsx

@martinheidegger
Copy link
Member

martinheidegger commented Dec 18, 2024

Hello @cmdcolin - I am happy to accept PR that block any tree shaking from happening. It would be great if you could look into the vite tree-shaking settings and see if that could work for you first though: https://dev.to/rafaelogic/optimizing-vuejs-performance-a-guide-to-tree-shaking-with-webpack-and-vite-3if7

amend: https://webpack.js.org/guides/tree-shaking/

@cmdcolin
Copy link
Author

I actually make a library that other people use so i would like to avoid too much that involves end users having to customize bundler settings.

I observed the same thing in both webpack and vite so far. my hypothesis is the manipulation of the globals could contribute to it, but i will have to check...

potentially those globals are pretty core to the library, so if it's out of scope, can close this too...

@martinheidegger
Copy link
Member

The end-users might use your library in combination with longfn in that case the final bundler will need to be setup for tree shaking. I am wondering if there is a "simple setting" that could take care of that. If there isn't, it is likely possible to split apart longfn in a lot of tiny files. I would accept a PR that does that.

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

No branches or pull requests

2 participants