photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

Make it tree-shakable #81

Open 5d-jh opened 1 year ago

5d-jh commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

5d-jh commented 1 year ago

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.

lvcabral commented 11 months ago

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 commented 8 months ago

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/upng-js@2.1.0

image

photopea commented 8 months ago

@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.