-
-
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
Update webpack and Vite istallation instructions for htmx 2.0 #2668
base: master
Are you sure you want to change the base?
Conversation
I think this should include import inject from '@rollup/plugin-inject' |
Also see #1690 |
Thanks @Darkproduct I've rewritten the docs to include your suggestions. To summarize there are the following options:
|
I am changing the Line 23 in 52b3570
Does this change these instructions at all? (Sorry I know nothing about Webpack or Vite) |
@1cg great to hear. Yes, the change allows us to simply inject/provide |
Is this possible in esbuild? I had to use a work around like so: https://discord.com/channels/725789699527933952/1252928586206154753/1252933134396428348 |
@jackielii |
This is going to be related too: #2629 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
import 'htmx.org'; | ||
``` | ||
|
||
However, you will probably need the global `htmx` variable, which gives your code access to methods like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I may offer a suggestion:
The use of "probably" is unclear to beginners; You give a very concrete example right after (the use of htmx plugins), but is this the only scenario?
Co-authored-by: Théophile Choutri de Tarlé <[email protected]>
build: {...}, | ||
plugins: [ | ||
inject({ | ||
htmx: 'htmx.org', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be: 'htmx.org/dist/htmx.esm'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@plooney81 As per @1cg comment here: #2668 (comment) htmx.org
uses htmx.esm.js
by default now.
Please see: https://github.com/bigskysoftware/htmx/blob/master/package.json#L23C3-L23C30
In other words htmx.org
should work (and works for me) well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This mimics my setup.
import './htmx.js'; | ||
|
||
// now you can import extensions | ||
import 'htmx-ext-debug/debug.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are describing a workaround which requires creating htmx.js
file to inject htmx
into the window
scope, so that the extensions can use it. It has to be done in a separate file, because ESM imports are asynchronous.
I have created a PR in the extensions repository, which eliminates the need of this workaround. With the new change extensions can be imported like this:
import `htmx.org`;
import `htmx-ext-extension-name`; // Replace `extension-name` with the extension name
It relies on the ESM import mechanism supported by most bundlers, including Webpack, Vite and Rollup.
Description
The webpack installation instructions are no longer valid for htmx 2.0. There are also no installation instructions for Vite.
This is affecting multiple people, judging from the issue tracker.
Corresponding issue:
Testing
It's a documentation update and the only way to test it is to follow the new guidelines. These new guidelines are what works for me and other people (see issues listed above).
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded