Skip to content

jazzband/django-pipeline

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5c9ee24 · Apr 18, 2024
Apr 17, 2024
Dec 27, 2023
Feb 17, 2023
Apr 17, 2024
Mar 19, 2024
Feb 10, 2023
Feb 21, 2023
Dec 3, 2023
Feb 9, 2023
Nov 10, 2021
Aug 6, 2022
Apr 18, 2024
Jan 22, 2018
May 25, 2017
Mar 9, 2023
Feb 20, 2023
Dec 3, 2023
May 9, 2019
Dec 9, 2020
Dec 21, 2023
Dec 21, 2023

Repository files navigation

Pipeline

Jazzband GitHub Actions Coverage Documentation Status

Pipeline is an asset packaging library for Django, providing both CSS and JavaScript concatenation and compression, built-in JavaScript template support, and optional data-URI image and font embedding.

Django Pipeline Overview

Installation

To install it, simply:

pip install django-pipeline

Quickstart

Pipeline compiles and compress your assets files from STATICFILES_DIRS to your STATIC_ROOT when you run Django's collectstatic command.

These simple steps add Pipeline to your project to compile multiple .js and .css file into one and compress them.

Add Pipeline to your installed apps:

# settings.py
INSTALLED_APPS = [
    ...
    'pipeline',
]

Use Pipeline specified classes for STATICFILES_FINDERS and STATICFILES_STORAGE:

STATICFILES_STORAGE = 'pipeline.storage.PipelineManifestStorage'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

Configure Pipeline:

# The folowing config merges CSS files(main.css, normalize.css)
# and JavaScript files(app.js, script.js) and compress them using
# `yuglify` into `css/styles.css` and `js/main.js`
# NOTE: Pipeline only works when DEBUG is False
PIPELINE = {
    'STYLESHEETS': {
        'css_files': {
            'source_filenames': (
                'css/main.css',
                'css/normalize.css',
            ),
            'output_filename': 'css/styles.css',
            'extra_context': {
                'media': 'screen,projection',
            },
        },
    },
    'JAVASCRIPT': {
        'js_files': {
            'source_filenames': (
                'js/app.js',
                'js/script.js',
            ),
            'output_filename': 'js/main.js',
        }
    }
}

Then, you have to install compilers and compressors binary manually.

For example, you can install them using NPM and address them from node_modules directory in your project path:

PIPELINE.update({
    'YUGLIFY_BINARY': path.join(BASE_DIR, 'node_modules/.bin/yuglify'),
})
# For a list of all supported compilers and compressors see documentation

Load static files in your template:

{% load pipeline %}
{% stylesheet 'css_files' %}
{% javascript 'js_files' %}

Documentation

For documentation, usage, and examples, see: https://django-pipeline.readthedocs.io

Issues

You can report bugs and discuss features on the issues page.

Changelog

See HISTORY.rst.