astro-htmx icon indicating copy to clipboard operation
astro-htmx copied to clipboard

Adding htmx extensions ?

Open RayyanNafees opened this issue 1 year ago • 7 comments

How to add htmx extensions using this like json-enc

RayyanNafees avatar Feb 25 '24 12:02 RayyanNafees

i think htmx's plugins are not supported

so your best bet at the moment is to add the script tag manually to your pages / layouts.

i will have to check if it's possible to include extensions in the plugin

excessivecoding avatar Feb 26 '24 12:02 excessivecoding

found this issue on the htmx repo. i will wait until something happen there but it seems to be a common issue with Vite / any bundler and using HTMX

https://github.com/bigskysoftware/htmx-extensions/issues/128

excessivecoding avatar Mar 04 '24 23:03 excessivecoding

all the integration does is... add the htmx script tag before initialisation

So.. what if we maintain an object with extension names & their urls like this

type ext = 'client-side-templates' | 'json-env' | 'ws' // ... all extensions available by htmx

const url = `https://unpkg.com/htmx.org/dist/ext/${ext}`

and then import it in the script tag the same way u add a script tag for htmx code.. in this integration

RayyanNafees avatar Jun 06 '24 14:06 RayyanNafees

I think this is going outside of the scope of this extension as this is using remote scripts.

If anybody needs HTMX extension, feel free to opt-out of astro-htmx and import it on your own

excessivecoding avatar Jun 16 '24 15:06 excessivecoding

I think this is going outside of the scope of this extension as this is using remote scripts.

What else u think is happening here ?

the script is actually remotely fetched from npm registry when we use unpkg.com.

In case u need npm-packages for imporing the extension are available as npm packages by user @carsongross

While adding extensions as dependencies might not be the ideal approach to go with... since it might bloat the integration with htmx extensions the developer might not need...

But having a way to integrate these with astro-htmx would be really helpful

RayyanNafees avatar Jul 09 '24 08:07 RayyanNafees

What else u think is happening here ?

@RayyanNafees there is a clear distinction between installing and bundling your own dependencies and serving from a CDN.

I will dig to find a proper solution but I don't think mixing bundled deps and CDN assets is the right call.

excessivecoding avatar Jul 10 '24 12:07 excessivecoding