ascorbic / unpic

Universal image CDN translator
https://unpic.pics/lib
280 stars 31 forks source link

Core as a set of plugins #96

Open benmccann opened 9 months ago

benmccann commented 9 months ago

We just launched @sveltejs/enhanced-img for static images included in the user's project and are now trying to figure out how to handle images from CDNs. I had proposed using @unpic/svelte as our solution there. However, an objection came up that it includes transformers and parsers for all CDNs instead of just the one that the user needs.

It would be nice if we could make core a set of plugins where the user could register just the CDNs they're going to use. Optionally, we could provide a convenience method which registers all providers.

It looks like including the library currently adds about 38 kB unminified and we could probably cut that down a fair amount.

https://github.com/ascorbic/unpic/issues/82 is a bit related to this idea as well

If there's some level of interest, I may be able to contribute to this

ascorbic commented 9 months ago

If you need just the transformers you can use unpic, which doesn't have any of the component stuff. The idea for Unpic has always been that it's zero-config. However an optional way of importing the CDNs individually could be a good one

benmccann commented 9 months ago

We do need the component. Maybe we could have just the Svelte component need to be configured? Or maybe it could be exported from the package twice? E.g. import { Image } from "@unpic/svelte"; could give a version which needs to be configured and import { Image } from "@unpic/svelte/full"; could give a version that contains all the providers already configured

(For what it's worth, I just watched this talk and saw at 10m that Angular requires you to configure a provider)

ascorbic commented 9 months ago

So I'm still not sold on the actual API within components, but I am publishing a version of the unpic lib with subpath exports for all transformers in the form unpic/transformers/cloudinary etc, and a separate export for unpic/detect. This means you can do detection without the barrel export, and can load the CDNs as needed, and can be a first step to working this out.