-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Management command for downloading HTMX #87
Comments
No the project deliberately doesn't bundle htmx or provide any way of doing so, since there are too many ways you might want to embed htmx - from a CDN, your own static files, or via a JS bundler npm, and with or without extensions. The download script there is to make the example app more manageable and you're free to adapt it. |
I reconsidered this after several further requests over the years. #428 has a possible implementation. |
if HTMX is an integral part of our development project, it seems useful to me to declare it as a parameter, as Django compressor does to perform this operation we need to add these news settings:
All news settings have the prefix HTMX_
Indicate the htmx version to download HTMX_EXTENSIONS = [
"htmx.js", # mandatory for django-htmx
"ext/debug.js", # mandatory for django-htmx
"ext/event-header.js", # mandatory for django-htmx
"https://github.com/orgname/repos/main/src/",
"https://raw.githubusercontent.com/bigskysoftware/htmx-extensions/main/src/head-support/head-support.js",
"https://unpkg.com/browse/htmx-ext@0.1.5/dist/csrf-token.js",
] By default HTMX_EXTENSIONS have these values:
we need to define where to store the download files HTMX_STATIC_ROOT = "static_htmx/"
# or
HTMX_STATIC_ROOT = "/opt/django_tuto/static_htmx/" HTMX_STATIC_ROOT is the original folder to collect the HTMX files with command downloadhtmx or htmx download HTMX_STATIC_URL = "htmx" by default the static URL for htmx STATIC_URL + HTMX_STATIC_URL After call the download hmtx command, we can call the collectstatic command. STATICFILES_DIRS = [
...
(HTMX_STATIC_URL, HTMX_STATIC_ROOT),
] On the html template we can use these to include the htmx files <script src="{% static 'htmx/myjsfile.js' %}"></script> With these settings, no need to pass extra arguments on the command line. just execute commands in this order python manage.py downloadhtmx (or htmx download)
python manage.py collectstatic What do you think ? |
Decided against this in #428. It’s a lot easier to write a script in your project that downloads all your third-party JS/CSS assets, using |
In my project I've created a management command based on https://github.com/adamchainz/django-htmx/blob/main/example/download_htmx.py.
Would it be desirable to include a management command directly in this project for this purpose?
The text was updated successfully, but these errors were encountered: