-
-
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
Add ES Module (ESM) support to the factory #2270
Comments
Hey, it seems (I know nothing about all this so you tell me 😆) we have esm support in v2 alpha, if you're willing to take a look and test if things work as expected? |
Nope, no luck. 2.0 doesn't export anything. And the extensions are not declared in the package.json file, either. I happen to know a thing or two about ESM, I am happy to help. Just say the word and I will gladly submit a patch. |
in v2.0 we have a .esm.js file that does export htmx: Line 3917 in f004978
|
Yes, I saw that, but that's not how you export an ESM module ;) |
I must have missed what export stands for. ;) And for the sake of everyone’s sanity, let’s not overcomplicate it for nothing. |
Would you like to elaborate on this...? I too have been laboring under the delusion that one exported ECMAScript modules with the |
Please excuse my previous response. I didn't explain it well. Let me try again: Yes, Again, super happy to provide a patch, with tests. If my help is still welcome ❤️🩹 |
is it an anonymous function? I thought it was a plain javascript object returned by the IIFE... |
Line 1 in f004978
It's exporting the outer wrapper, not the object. Both would not be leading to the desired result. The latter would allow at least something like |
Appreciated! And don't worry about it.
Correct me if I'm wrong, but the current |
Oh, I know exactly what you're talking about—you can't export anonymous objects from an export statement i.e. the Is the change you were going to suggest just |
I am adding myself to this as I also need ESM exports to allow reuse. there are some hacks to overcome it.... https://github.com/terrablue/htmx-esm btw, is used by https://github.com/primatejs/primate |
If this is implemented, it would be nice to add deep exports in I would be more than happy to get rid of the needless vendoring, seeing as I need to update it every time a new HTMX version comes out. |
Yes, I mentioned that in the original ticket report. I will submit a patch for that. |
Yes, I believe this would be most consistent with the docs, where you call |
Since there seems to be plenty of traffic on this issue, I will submit a patch targeting the 2.0 release. |
I looked at the code for 2.0 and decided to discontinue using HTMX. Maybe someone else will pick this up someday. |
Would you like to share what it was about the 2.0 code that discouraged you? It's really not that different |
Hi @alexpetros, I would rather not discourage anyone. I know how much work goes into a project this size. Thus, will stick to errors:
As a personal note: Tools like Wireit and Rollup or ESbuild might make the build processes more smooth. Lifting browser support to Baseline 2023 might also simplify things. I appreciate the effort put into this package <3 We use mostly Web Components and are fairly happy writing JavaScript code and have maybe not the ideal user profile. |
Ok! Well, anyway, we're going to switch to default exports for htmx 2.0: #2428 |
Hi there 👋,
Currently, the factory supports AMD, CJS and browser environments.
However, modern websites and browsers have proper module (ESM) support.
Let's say you want to do something like this:
Your browser will tell you that
htmx.org
doesn't export a default. Similarly, something like this also does not work:Both are completely valid use cases and have, as of writing this, over 97% browser support.
I think adoption would be rather simple. Everything already works in NodeJS or rather CommonJS (CJS). All that's needed would be to extend the factory to export ESM modules in a browser.
If you want to take this one step further, we could also consider to properly defining entry points via NodeJS' exports. This would be particularly helpful if you wish to load extensions.
I would be happy to contribute a small patch.
Cheers!
Joe
The text was updated successfully, but these errors were encountered: