I am trying to use PhotoSwipe in an Aurelia project, but cannot find a way to make it work.
In my aurelio.json under bundles, I have:
{
"name": "photoswipe",
"path": "../node_modules/photoswipe/dist/",
"main": "photoswipe.min",
"resources": [
"photoswipe-ui-default.min.js",
"photoswipe.css",
"default-skin/default-skin.css"
]
}
in my package.json, I have:
"@types/photoswipe": "^4.0.27",
"photoswipe": "^4.1.1"
in my .ts module, I have
import PhotoSwipe from 'photoswipe';
The code I use for opening the gallery (just copied from the getting started doc)
imageClicked() {
var pswpElement = document.querySelectorAll('.pswp')[0];
// build items array
var items = [
{
src: 'https://placekitten.com/600/400',
w: 600,
h: 400
},
{
src: 'https://placekitten.com/1200/900',
w: 1200,
h: 900
}
];
// define options (if needed)
var options = {
// optionName: 'option value'
// for example:
index: 0 // start at first slide
};
// Initializes and opens PhotoSwipe
var gallery = new PhotoSwipe<PhotoSwipeUI_Default.Options>(pswpElement as HTMLElement, PhotoSwipeUI_Default, items, options);
gallery.init();
}
The aurelia project builds ok, but runtime i get this error:
Uncaught ReferenceError: PhotoSwipeUI_Default is not defined
I tried adding export to the aurelia.json bundle
"exports": [ "PhotoSwipe", "PhotoSwipeUI_Default" ]
This didn't change anything.
I tried various import statements:
import PhotoSwipeUI_Default from 'photoswipe'; // Now PhotoSwipeUI_Default is of type PhotoSwipe
import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default' // Module not found compile error
import PhotoSwipeUI_Default from 'npm:photoswipe@4.1.1/dist/photoswipe-ui-default.min.js'; // Cannot find module
I am in the dark, and my trial and error method of resolving this is going no where.
What am I missing?