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

Make it tree-shakable #81

Open
5d-jh opened this issue Jun 23, 2023 · 10 comments · May be fixed by #84
Open

Make it tree-shakable #81

5d-jh opened this issue Jun 23, 2023 · 10 comments · May be fixed by #84

Comments

@5d-jh
Copy link

5d-jh commented Jun 23, 2023

Similar to this issue

I'm using this library with bundled by Webpack.

In my case, I only use decode function. However since this library is wrapped by an object, bundled file includes pako which seems not used when decoding.

This results unnecessary large bundle size.

@photopea
Copy link
Owner

yes, pako.js is needed only for encoding, not for decoding. You can manually delete the encoding parts from the UPNG.js file.

@5d-jh
Copy link
Author

5d-jh commented Jun 23, 2023

Yes, for now I'm using this library with encoding parts deleted.

But for everyone(including me) that want to use tree-shaked version, removing implementatinos that are not familiar with doesn't seem right.

Since this library doesn't have a lot of functions, it can be easily done. If you are okay with this, may I take over this issue?

@photopea
Copy link
Owner

What are your plans? Do you want to make two files? There are certain parts needed both by an encoder and by a decoder.

@5d-jh
Copy link
Author

5d-jh commented Jun 26, 2023

No I'm not separating into multiple files. Just going to use export clause to each public function so let bundlers know which parts of the code are actually used.

This is example of tree-shakable version that I was talking of:

import pako from 'pako';

export function encode() {
   ...
  someInternal()
}

export function decode() {
  pako.dosomething();
  someInternal()
  ...
}

function someInternal() {
 ...
}

@5d-jh
Copy link
Author

5d-jh commented Jun 26, 2023

My plan is to publish tree-shakable version as v3, and keep current version stay in v2 to prevent you from forcing adopt new toolchains(webpack, npm, etc...).

@photopea
Copy link
Owner

I can not use that code, as I want my program to be written in Javascript

@5d-jh
Copy link
Author

5d-jh commented Jun 26, 2023

That's not true.

export is part of JavaScript syntax, and can be used on any platform(browser, nodejs) right in.

see JavaScript modules and Tree shaking.

@5d-jh 5d-jh linked a pull request Jul 28, 2023 that will close this issue
@lvcabral
Copy link

lvcabral commented Nov 22, 2023

I also think to use pako makes this package bigger than it needs, can't you use something like:
https://www.npmjs.com/package/fflate

I made a fork and changed the module to fflate
https://github.com/lvcabral/UPNG.js

@danielbarion
Copy link

Hey guys! I found this project while testing photopea (also, great work on it @photopea!)

About the bundle size, if UPNG is tree-shakeable this will save almost 75% of the bundle size:

@photopea please take a look at this:

https://bundlephobia.com/package/[email protected]

image

@photopea
Copy link
Owner

@danielbarion I am so confused. The UPNG.js library is 46.6 kB now, and it is 14.5 kB GZipped. If you want it to be small, do not use that tool that you are referring to.

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 a pull request may close this issue.

4 participants