Git Product home page Git Product logo

django-node-assets's Introduction

Django-node-assets

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'

Note

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

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

NODE_MODULES_ROOT = '/var/assets/node_modules'

Note

A base dir must be called node_modules.

Specify path to the node package manager executable (optional)

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

Note

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

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>

django-node-assets's People

Contributors

proofit404 avatar whitespy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.