1

I've pinned photoswipe:

./bin/importmap pin photoswipe --download

in app/javascript/application.js I've added

import PhotoSwipeLightbox from 'photoswipe'
document.addEventListener("turbo:load", function() {
  const lightbox = new PhotoSwipeLightbox({
    gallery: '#existing-files',
    children: '.gal',
    pswpModule: () => import('photoswipe')
  });
  lightbox.init();
});

The lightbox opens straight away on page load but the image is missing. pswpModule: () => import('photoswipe') doesn't appear to work but no error is given.

Mark Robinson
  • 1,479
  • 2
  • 15
  • 34

1 Answers1

1

I worked it out. I needed:

./bin/importmap pin photoswipe --download
./bin/importmap pin photoswipe/lightbox --download

then

import PhotoSwipeLightbox from 'photoswipe/lightbox'
Mark Robinson
  • 1,479
  • 2
  • 15
  • 34