Metadata-Version: 2.4
Name: django-node-assets
Version: 0.9.16
Summary: The Django application that allows to install and serve assets via Node.js package manager infrastructure.
Author-email: Andrey Butenko <whitespysoftware@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Andrey Butenko
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: GitHub, https://github.com/whitespy/django-node-assets
Keywords: django,assets,staticfiles,Node.js,npm,package.json
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Description-Content-Type: text/x-rst
License-File: LICENSE.txt
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

##################
Django-node-assets
##################

.. image:: https://badge.fury.io/py/django-node-assets.svg
    :target: https://badge.fury.io/py/django-node-assets

.. image:: https://img.shields.io/badge/linter-ruff-FF69B4
    :target: https://github.com/astral-sh/ruff

.. image:: https://github.com/whitespy/django-node-assets/actions/workflows/code_quality_check.yml/badge.svg
    :target: https://github.com/whitespy/django-node-assets/actions/workflows/code_quality_check.yml

|

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
------------

.. code:: bash

    $ pip install django-node-assets

Configuration
-------------

Add 'django_node_assets' to your INSTALLED_APPS:

.. code:: python

    INSTALLED_APPS = [
        ...
        "django_node_assets",
    ]

Add NodeModulesFinder to STATICFILES_FINDERS:

.. code:: python

    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:

.. code:: python

    NODE_PACKAGE_JSON = "/var/assets/package.json"

.. note::

    A package.json must have the "dependencies" section and look like:

    .. code:: json

        {
            "dependencies": {
                "jquery": "^3.2.1",
                "bootstrap": "^3.3.5"
            }
        }

    Details here: https://docs.npmjs.com/files/package.json#dependencies


Specify the absolute path to a directory where the **npminstall** management command will install assets:

.. code:: python

    NODE_MODULES_ROOT = "/var/assets/node_modules"

.. note::

    A base dir must be called **node_modules**.

Override path to the node package manager executable (optional)

.. code:: python

    NODE_PACKAGE_MANAGER_EXECUTABLE = "/usr/local/bin/npm"

.. note::

    The node package manager must be already installed in your system.

Override options of the node package manager install command (optional)

.. code:: python

    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

.. code:: bash

    $ python manage.py npminstall

Use Django's static template tag to link installed assets

.. code:: html

    {% 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>
