xstevenyung / astro-htmx

Easily install HTMX into your Astro project
69 stars 3 forks source link

Adding htmx extensions ? #4

Open RayyanNafees opened 8 months ago

RayyanNafees commented 8 months ago

How to add htmx extensions using this like json-enc

xstevenyung commented 8 months ago

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

xstevenyung commented 8 months ago

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/issues/1690

RayyanNafees commented 4 months ago

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

xstevenyung commented 4 months ago

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

gedw99 commented 4 months ago

@xstevenyung

But htmx 2.0 leans heavily on extensions such as ws, sse and a ton of there things. So with supporting extensions this astro extension becomes very limited if not useless.

RayyanNafees commented 3 months ago

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

xstevenyung commented 3 months ago

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.