EOX-A / EOxElements

A Web Component collection of geospatial UI elements, crafted by EOX.
https://eox-a.github.io/EOxElements/
MIT License
12 stars 2 forks source link

Element publishing improvements #747

Open silvester-pari opened 7 months ago

silvester-pari commented 7 months ago

We're currently bundling all elements, no matter if they are supposed to be used in apps or via CDN. This seems to be a bad practice as it increases bundle size, and makes development harder. See https://lit.dev/docs/tools/publishing/#don't-bundle-minify-or-optimize-modules:

Don't bundle, minify, or optimize modules

Bundling and other optimizations are application concerns. Bundling a reusable component before publishing to npm can also introduce multiple versions of Lit (and other packages) into a user's application since npm can't deduplicate the packages. This causes bloat and may cause bugs. Optimizing modules before publication may also prevent application-level optimizations. Bundling and other optimizations can be valuable when serving a module from a CDN, but since users may need to use multiple packages that depend on Lit, serving from a CDN can result in users loading more code than necessary. For these reasons we recommend performance-sensitive applications always build from npm where packages can be deduplicated, rather than loading bundled packages off of a CDN. If you want to support usage from a CDN, we recommend making a clear separation between the CDN modules and the modules intended for production use. For example, placing them in a separate folder, or only adding them as part of a GitHub release and not adding them to the published npm module.

silvester-pari commented 6 months ago

I am still not sure how to handle imports with Lit. On the one hand, importing only the custom element class is nicer for treeshaking and preventing double imports, but on the other hand the custom elements are not defined this way (needs to import the entire file).

To tackle the "double definition" customElements error, a workaround was introduced in https://github.com/EOX-A/EOxElements/pull/746, but I'm not sure if this is a good permanent solution.