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

How to get it to work with ES6 Modules (if you're finding it isn't working) #387

Open
isabel-anastasiadis-boost opened this issue Nov 16, 2023 · 0 comments

Comments

@isabel-anastasiadis-boost

When we switched from using Webpacker to Vite to bundle our javascript, the initialisation broke.

We were doing:

import 'justifiedGallery/dist/js/jquery.justifiedGallery'

document.addEventListener('DOMContentLoaded', () => {
  // do our initialisation
})

With Vite, it seems that a different code path gets hit, and the import returns a function that we need to call to bind justifiedGallery with jquery. So this worked for us:

import bindJustifiedGalleryToJQuery from 'justifiedGallery/dist/js/jquery.justifiedGallery'

// `jquery.justifiedGallery.js` exports this function on line 13.
// It takes a "root" (in case jquery isn't defined yet and it has to find it) and jquery.
// But if you provide jquery, then it doesn't need the root.
bindJustifiedGalleryToJQuery(null, $);

document.addEventListener('DOMContentLoaded', () => {
  // do our initialisation
})

Not sure if this is the intended behaviour or not, but posting this in case other people run into similar problems.

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