-
Notifications
You must be signed in to change notification settings - Fork 55
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
Provide ESM support and add minified versions #123
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for htmx-extensions canceled.
|
I'm not sure this makes sense since it ties you a particular version of htmx |
In this docs PR, they seem to imply that you can already do: import 'htmx-ext-debug/debug.js'; |
@scrhartley Simon, thank you for your comments. Regarding moving
You are right about htmx updating more often than any of the extensions. The dependency ties you to a minimum version of
I see. I imagine a version conflict if somebody is, let's say, strictly using version I this case they should upgrade from What I can do is to make sure the minimum version of htmx that each extension requires really represents the lowest possible version it can function with. Anyways, this change does not break existing ways of integrating htmx extensions, so I don't think this should be a concern to stop the PR. What do you think?
The docs PR you mentioned is describing a workaround, which requires creating a separate This PR fixes the root cause which has created the need for the workaround. With this PR there is no need to create a separate import `htmx.org`;
import `htmx-ext-extension-name`; // Replace `extension-name` with the extension name I have updated the description of this PR to reference the workaround, and I have also left a comment in bigskysoftware/htmx#2668. I hope that answers your concern. |
I appreciate the detailed reply. For the IIFE change, for the files previously without it, they don't seem to fall into the use cases described in the page you linked. |
@scrhartley Yes it's mainly for consistency with the other 14 extensions which are already are in the IIFE form. If you have a concern about this change please let me know and I will revert it. It's not very important for the scope of the PR. |
Change 1: ESM import and bundler support
Make it possible to import extensions as ESM modules and use bundlers (e.g. Webpack, Vite, Rollup).
npm install htmx-ext-extension-name
and integrate them using<script src="node_modules/htmx-ext-extension-name/extension-name.js"></script>
import 'htmx-ext-extension-name';
results inUncaught ReferenceError: htmx is not defined
htms.js
file to injecthtmx
inwindows
scope so that the extension can use the. It has to be done in a separate file because ESM imports are asynchronous. This PR elminates the need for the workaround and allows to integrate HTMX and extensions in much cleaner way using ESM imports. Most bundlers support this by default (e.g. Webpack, Vite, Rollup).This change solves 4 issues:
Change 2: Minified versions
Add minified extension script versions to
unpkg.com/htmx-ext-extension-name
.unpkg.com/htmx-ext-extension-name/dist/extension-name.js
unpkg.com/htmx-ext-extension-name/dist/extension-name.min.js.gz
This change solves 2 issues:
Consistency with core htmx and documentation
The change is implemented following the approach of the core htmx library.
Documentation is updated in a corresponding pull request in the core htmx repository: bigskysoftware/htmx#3078.
Extra steps in deployment
This change adds 3 extra steps when publishing extensions to npm and require to run the following shell commands from the base directory of this repository.
npm install
to install uglify-js dependency, which does the script minificationchmod +x scripts/dist-all.sh
to add permissions executing thescripts/dist-all.sh
script fromnpm
npm run dist
to execute the script which generates IIFE, min, gzip and ESM versions of all extensions and adds them to adist
directory in each extensions folder. This command also prints the updated CDN script tags with latest version number and SRI hash to make documentation updates easier.Guide for reviewers
This update changes 57 files in the repository because it touches boilerplate code. Here is an overview of the key changes.
Changes in the root and
scripts
directories (4 files):dist
with distribution files in IIFE, min, gzip and ESM formats. It is heavily inspired of the dist script of the core htmx library and the test-all script.uglify-js
dependency and make it possible to runscripts/dist-all.sh
fromnpm
.npm install
based onpackage.json
and the old version is therefore overridden. I believe that the old version is just a copy-paste leftover from when this repository was split out of the core repository, but please let me know if I am mistaken.Changes in extension directories
src/extension-name
(53 files):extension-name.js
- extensions which were not following IIFE are now wrapped (10 files)package.json
of all extensions have been updated (23 files):"htmx.org": "^2.0.2"
is moved fromdevDependencies
todependencies
"main": "extension-name.js"
is replaced with"main": "dist/extension-name.esm.js",
"unpkg": "dist/extension-name.min.js"
is addedmain
andunpkg
properties have been added afterversion
andhomepage
properties for consistency, following the package.json file of the core htmx package."homepage": "https://htmx.org/extensions/extension-name/"
propertypackage-lock.json
has been automatically updated based on changes inpackage.json
(20 files)