Skip to main content

The Django application that allows to install and serve assets via Node.js package manager infrastructure.

Project description

https://badge.fury.io/py/django-node-assets.svg https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336 https://img.shields.io/badge/code%20style-black-000000.svg https://github.com/whitespy/django-node-assets/actions/workflows/code_quality_check.yml/badge.svg

The Django application that allows to install and to serve static assets via Node.js package manager infrastructure. The application exposes 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` metatadata 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>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_node_assets-0.9.14.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

django_node_assets-0.9.14-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file django_node_assets-0.9.14.tar.gz.

File metadata

  • Download URL: django_node_assets-0.9.14.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for django_node_assets-0.9.14.tar.gz
Algorithm Hash digest
SHA256 d5b5c472136084d533268f52ab77897327863a102e25c81f484aae85eb806987
MD5 bb078d184ddac261e619412a754a910b
BLAKE2b-256 860e7c7e10db716883008be9685c642449939b75b1b76eaf29f60da663bfde74

See more details on using hashes here.

File details

Details for the file django_node_assets-0.9.14-py3-none-any.whl.

File metadata

File hashes

Hashes for django_node_assets-0.9.14-py3-none-any.whl
Algorithm Hash digest
SHA256 80cbe3d10521808309712b2aa5ef6d69799bbcafef844cf7f223d3c93f405768
MD5 800130dfa1b18688cd7e384eb4b3d4f6
BLAKE2b-256 145b1ccd8fcc24c5c7d655334784a651d59ab81ae11b4875ecf1c80c2a6e57a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page