Skip to main content

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

Project description

https://travis-ci.org/whitespy/django-node-assets.svg https://badge.fury.io/py/django-node-assets.svg https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336

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 nmpinstall management command will install assets:

NODE_MODULES_ROOT = '/var/assets/node_modules'

Specify path to the node package manager executable (optional)

NODE_PACKAGE_MANAGER_EXECUTABLE = '/usr/local/bin/npm'

Usage

Call the nmpinstall 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.9.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

django_node_assets-0.9.9-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file django-node-assets-0.9.9.tar.gz.

File metadata

  • Download URL: django-node-assets-0.9.9.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for django-node-assets-0.9.9.tar.gz
Algorithm Hash digest
SHA256 fcbaac9b1d4fd86d72270d8ba5475f0b7412bc051d9cbdd7fe61e730114ac7ca
MD5 08e0bff9325483aa802aee5fa4b78f54
BLAKE2b-256 9214eb6b7c2477cc63cd8166f2d27bef1e6b299d2bc994a70996f2512bc876f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_node_assets-0.9.9-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for django_node_assets-0.9.9-py3-none-any.whl
Algorithm Hash digest
SHA256 697ba77d816e3c6fec1373d255ddc0a705c72cd474da3f962fb441b3998a72e3
MD5 6dc8254a810c052a815437cedcba23aa
BLAKE2b-256 8800f48ef4318400edd3e3cc483b8993731283c9d66604e987f6b92367b8b571

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