-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 enable extensions in a es6 module using importmap #2398
Comments
Do you need more than a simple htmx.logAll()? |
No, I'm a newbie that I simply googled "htmx debug" and saw the extension. But in fact, logAll() does exactly what I was looking for. Thanks!! |
Reopening, because the original issue of how to enable extensions persists. import 'htmx.org/dist/ext/client-side-templates.js'; Same error:
Is there a way to "connect" htmx to the extension in javascript, to avoid this error? |
I used to have the problem frequently with jquery plugins, saying jquery wasn't defined. Here's the actual offending code. /**
* Bundled by jsDelivr using Rollup v2.79.1 and Terser v5.19.2.
* Original file: /npm/[email protected]/dist/ext/client-side-templates.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
htmx.defineExtension("client-side-templates", {
transformResponse: function(e, t, r) {
var n = htmx.closest(r, "[mustache-template]");
if (n) {
var a = JSON.parse(e)
, s = n.getAttribute("mustache-template");
if (S = htmx.find("#" + s))
``` |
I think they are working on improving that for v2. But I can’t say for sure. |
I see #1655 also mentions importmaps and es6, I'll change the title because indeed that's the key issues. es6 and javascript modules are great, and importmaps eliminate the need for build systems. I hope it get solved! |
I see in #2579 that there's a 2.0 beta now! Hopefully these extensions will be able to be included as modules, as I see that @Telroshan has tagged with with 2.0. Let me know when/how to test! |
Hey, unfortunately I'm a bit lost when it comes to those modules stuff, though for htmx 2 we moved extensions to a separate repository, where each extension now has its own npm package. |
Coming in after the 2.0.0 release: My workaround was to fall back to script tags, but save the htmx.js and htmx-ext-ssr.js libs to my device and serve them myself with script tags (as htmx documents in their examples) for offline functionality |
@1klap I also use importmaps and the following works for me : I updated to Then I added this line to the top of you might also need to load a
|
For me works in app.js:
My import map:
|
@tacman @andryyy @1klap @donseba @edgmic good news - I implemented the possibility to import HTMX extensions as ESM modules in this PR. Please check it out. If it gets merged, it will be possible to do this without workarounds: import `htmx.org`;
import `htmx-ext-extension-name`; // Replace `extension-name` with the extension name |
I've install html and the debug extension, and have loaded them in app.js
This fails with
The documentation show unpkg, but I'm working on an offline project and it needs to run locally, via a downloaded file from jsdelivr.
If I simply import it,
I get this:
Thanks.
The text was updated successfully, but these errors were encountered: