The Django application that allows installing and serving static assets via Node.js package manager infrastructure. The application exposes a management command to install dependencies from your package.json and several static files finders to find files from installed node packages and exclude metadata of node packages and unwanted files when static files will be collected via Django’s collectstatic management command execution.
Features
Avoiding vendoring static assets in your repository like jQuery plugins, Bootstrap toolkit, etc
Avoiding mess in STATIC_ROOT through exclusion node packages’ metadata and unwanted files
Installing dependencies by Django’s management command
Installation
$ pip install django-node-assets
Configuration
Add ‘django_node_assets’ to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_node_assets",
]
Add NodeModulesFinder to STATICFILES_FINDERS:
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"django_node_assets.finders.NodeModulesFinder",
]
Specify absolute path to the package.json file:
NODE_PACKAGE_JSON = "/var/assets/package.json"
Specify the absolute path to a directory where the npminstall management command will install assets:
NODE_MODULES_ROOT = "/var/assets/node_modules"
Override path to the node package manager executable (optional)
NODE_PACKAGE_MANAGER_EXECUTABLE = "/usr/local/bin/npm"
Override options of the node package manager install command (optional)
NODE_PACKAGE_MANAGER_INSTALL_OPTIONS = ["--dry-run"]
Defaults to –no-package-lock, –production.
Usage
Call the npminstall management command to install dependencies specified in the package.json
$ python manage.py npminstall
Use Django’s static template tag to link installed assets
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/dist/css/bootstrap.min.css' %}">
<!-- Some amazing markup -->
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'bootstrap/dist/js/bootstrap.js' %}"></script>
Metadata
Release files for django-node-assets 0.9.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_node_assets-0.9.16.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_node_assets-0.9.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / django_node_assets-0.9.16.tar.gz
| Download URL | django_node_assets-0.9.16.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a7fcaf0337153b4579cf98a18862362752ccea545d8253a434cdd1d43042289
|
|
BLAKE2b-256 checksum How to use checksums |
620032c09894e6ad580667d73a5cf046a47740aad8fdc7a5f24ce57af998800d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / django_node_assets-0.9.16-py3-none-any.whl
| Download URL | django_node_assets-0.9.16-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62bc9ccbebf1917df5df61eaf338bc057fd86f08cbdc11c26d1210227706c829
|
|
BLAKE2b-256 checksum How to use checksums |
6e5f62641e1a766009844199c07d8dcf7824a7bcac083d93b5b7df510992a56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|