Compile and Compress Assets with django-pipeline

Using things like CoffeeScript, Stylus, Less, SASS/SCSS, etc... Is becoming a more and more core part of development, but the problem usually is compiling these assets for use on our site. With django-pipeline this process is now much easier in both development and production. Learn the few easy steps it takes to get started with it.

resources

base.html

{% load compressed %}
<!doctype html>
<html>
  <head>
    <title>{% block title %}Django Store{% endblock %}</title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
    {% compressed_css 'main' %}
    {% compressed_js 'vendor' %}
    {% compressed_js 'main' %}
    <script>
    $('.carousel').carousel();
    </script>
  </head>
<body>
  ...
</body>
</html>
settings.py
INSTALLED_APPS = (
    'pipeline',
)

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE_COMPILERS = (
    'pipeline.compilers.coffee.CoffeeScriptCompiler',
    'pipeline.compilers.stylus.StylusCompiler',
)

PIPELINE_JS = {
    'main': {
        'source_filenames': (
            'coffee/app.coffee',
        ),
        'output_filename': 'js/main.js',
    },
    'vendor': {
        'source_filenames': (
            'vendor/jquery.min.js',
            'vendor/bootstrap.min.js',
        ),
        'output_filename': 'js/vendor.js',
    }

}

PIPELINE_CSS = {
    'main': {
        'source_filenames': (
            'stylus/main.styl',
        ),
        'output_filename': 'css/main.css',
    }
}
comments powered by Disqus