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

Asset Manager can't load .esm Modules #3783

Open
wernerjoss opened this issue Dec 30, 2023 · 2 comments
Open

Asset Manager can't load .esm Modules #3783

wernerjoss opened this issue Dec 30, 2023 · 2 comments

Comments

@wernerjoss
Copy link

I just stumbled over a Problem with Javascript esm Module loading via Asset Manager as described in the docs - it turned out that it looks like being impossible to do this.
my example was photoswipe slideshow, which is only provided as an esm Module.
I tried with several Options (loading...) but none worked.
So, I guess, this is a feature request.

@rhukster
Copy link
Member

rhukster commented Jan 5, 2024

Can you provide an example of the twig you are using and what you expect the output to be?

@wernerjoss
Copy link
Author

wernerjoss commented Jan 5, 2024

yes, sure - in twig, I can load the desired esm Modules like so:

`

<script type="module"> import PhotoSwipeLightbox from 'https://unpkg.com/[email protected]/dist/photoswipe-lightbox.esm.js'; import PhotoSwipe from 'https://unpkg.com/[email protected]/dist/photoswipe.esm.js'; import PhotoSwipeSlideshow from 'https://cdn.jsdelivr.net/gh/htmltiger/photoswipe-slideshow/photoswipe-slideshow.esm.min.js'; const lightbox = new PhotoSwipeLightbox({ gallery: '#photoswipe-gallery-id', pswpModule: PhotoSwipe, children: 'a'}); const slideshowPlugin = new PhotoSwipeSlideshow(lightbox,6); // statt 4 sec lightbox.init(); </script>

`
which seems to work, if used in a theme's base.html.twig, as it is just pure html.
my intention, however, is to load these in a plugin (PhotoswipeExtension.php), like so:

`
sprintf('import PhotoSwipeLightbox from "https://unpkg.com/[email protected]/dist/photoswipe-lightbox.esm.js";'),

sprintf('import PhotoSwipe from "https://unpkg.com/[email protected]/dist/photoswipe.esm.js";'),

sprintf('import PhotoSwipeSlideshow from "https://cdn.jsdelivr.net/gh/htmltiger/photoswipe-slideshow/photoswipe-slideshow.esm.min.js";'),

sprintf('const lightbox = new PhotoSwipeLightbox({ gallery: "#photoswipe-gallery-id", pswpModule: PhotoSwipe, children: "a"});'),

sprintf('const slideshowPlugin = new PhotoSwipeSlideshow(lightbox,6);'),

sprintf('lightbox.init();'),

`
but this simply does nothing, no modules loaded visible in debugger.
same happens when I copy the modules from upkg to local file system and try to load from there.

I also tried to add the modules via
$this->grav['assets']->addJsModule(...)
which I expected to do just that: load a javascript (esm) module
and
$this->grav['assets']->addJs(...)
with the same result: nothing loaded.

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

2 participants