Lightweight JavaScript ESM module loader for Django.
Project description
Django ESM
NextGen JavaScript ESM module support for Django.
Highlights
- easy transition
- smart cache busting
- no more bundling
- native ESM support
- local vendoring with npm
Setup
Install the package and add it to your INSTALLED_APPS
setting:
pip install django-esm
# settings.py
INSTALLED_APPS = [
# …
'django_esm',
]
Next, add the node_modules directory to your staticfiles finders:
# settings.py
STATICFILES_DIRS = [
BASE_DIR / "node_modules",
]
Finally, add the import map to your base template:
<!-- base.html -->
<!DOCTYPE html>
{% load esm %}
<html lang="en">
<head>
<script type="importmap">{% importmap %}</script>
</head>
</html>
That's it!
Don't forget to run npm install
and python manage.py collectstatic
.
Usage
You can now import JavaScript modules in your Django templates:
<!-- index.html -->
{% block content %}
<script type="module">
import "htmx.org"
htmx.logAll()
</script>
{% endblock %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django_esm-0.1.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for django_esm-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b3c138b6974e8b4af0a15bb2b56816c973005bbf8a9e96656cd59d97492e81 |
|
MD5 | ac8e4e7735b4a6dce1a2e2bb45f3ea6f |
|
BLAKE2b-256 | 10a9edf1be10e3092975a369ac72c0717eb77c61f4b506d4e02cf7f9483f4530 |