I’m using twitter bootstrap and django. I’ve got my dependencies handled with a pip requirements file.
I’ve got 2 questions:
- How can I use less while I’m developing so it’ll get compiled when I edit one of my less files?
- How can I create some kind of build script that will compress and combine my JS and generate CSS from Less as part of a deployment?
I’ve written a custom build script that creates a virtualenv, runs ‘pip install -r requirements.txt’, django syncdb, django migrate and then off we go.
What’s the easiest way of integrating less into this?
Thanks
Install django-static-precompiler:
Run
pip install django-static-precompilerAdd
static_precompilerto INSTALLED_APPSInstall lessc executable, either via your package manager or run
npm install less(npm is node package manager, which should be distro-installable, use at last resort)Use less in templates:
Load the template tag:
{% load less %}Use less template tag:
<link rel="stylesheet" href="{{ STATIC_URL}}{% less "path/to/styles.less" %}" />Note that by default compiled files are saved into
COMPILEDfolder under yourSTATIC_ROOT(orMEDIA_ROOTif you have noSTATIC_ROOTin your settings). You can change this folder name withSTATIC_PRECOMPILER_OUTPUT_DIRsetting. See the documentation for further details.I didn’t try it personally but i know that django-compressor also supports less.