trvswgnr / bs5-lightbox

A pure JS lightbox gallery plugin for Bootstrap 5 based on the Modal and Carousel components
https://trvswgnr.github.io/bs5-lightbox/
MIT License
129 stars 28 forks source link

why are bs components bundled? #5

Closed dkern closed 2 years ago

dkern commented 2 years ago

Hello,

I was about to use your lightbox, because it would fit my needs and works great so far. But why do you bundle carousel and modal within the script file? If a site already uses BS5, why not reuse the code, instead of include it twice?

trvswgnr commented 2 years ago

If i remember correctly, Bootstrap adds the event listeners in the component files within the individual component files, so when I tried to import them it would make two instances of the modal backdrop on click and mess up carousel navigation. I'm certain there's a better way where the BS5 code can be reused, I just don't know what it is yet.

patrickhrastnik commented 2 years ago

I'd suggest to add bootstrap as an NPM dependency and to import the package as-is. This provides a way to create a bundled version, but does not influence use cases which import their own bootstrap package.

This would make the local imports from ./bootstrap/model and ./bootstrap/carousel obsolete, and the custom declaration for bootstrap can be replaced with a proper import:

import * as bootstrap from 'bootstrap';
trvswgnr commented 2 years ago

That’s the plan, and Bootstrap is already listed as a dependency. The problem, if I remember correctly, comes from compiling the CDN version, where importing from Bootstrap bundles the entire package. I’ll fix this in the next release.

trvswgnr commented 2 years ago

@dkern @patrickhrastnik Bootstrap components are no longer included in the package as of v1.8.0.