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

Works fine locally (NPM/Webpack) but breaks when in production #40

Closed
xdcha opened this issue Nov 8, 2022 · 1 comment
Closed

Works fine locally (NPM/Webpack) but breaks when in production #40

xdcha opened this issue Nov 8, 2022 · 1 comment

Comments

@xdcha
Copy link

xdcha commented Nov 8, 2022

Firstly, thanks for creating such a great plugin. Seems to work brilliantly when I run it locally. In production, however, it breaks. No console errors and when you click an image you are just taken to the source in a new window. I am using Bootstrap 5.

Am I doing something wrong?

App.js (entry file)

import 'bootstrap';
import 'bs5-lightbox';

File.html

<a href="../img/inv-item.jpeg" data-toggle="lightbox" data-gallery="hero-inv-gallery" class="ratio ratio-1x1  col-6">
    <img class="c-ofc" src="../img/inv-item.jpeg" class="img-fluid">
</a>
<a href="../img/inv-item2.jpg" data-toggle="lightbox" data-gallery="hero-inv-gallery" class="ratio ratio-1x1 col-6">
    <img class="c-ofc" src="../img/inv-item2.jpg" class="img-fluid">
</a>
<div data-src="../img/inv-item2.jpg" data-toggle="lightbox" data-gallery="hero-inv-gallery"></div>
<div data-src="../img/inv-item2.jpg" data-toggle="lightbox" data-gallery="hero-inv-gallery"></div>
<div data-src="../img/inv-item3.jpg" data-toggle="lightbox" data-gallery="hero-inv-gallery"></div>

When I view the source js file in production there is no reference to data-toggle but there is in development mode.

Appreciate any advice/guidance.

@xdcha
Copy link
Author

xdcha commented Nov 8, 2022

Would appear it does not automatically initialise for me.

import Lightbox from 'bs5-lightbox';
document.querySelectorAll('[data-lightbox]').forEach(el => el.addEventListener('click', Lightbox.initialize));

This indeed solves it.

@xdcha xdcha closed this as completed Nov 8, 2022
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

No branches or pull requests

1 participant