I thought I provided the best solution I have found so far, but please feel free to suggest the best alternatives.
The biggest problem interfering with my requirement is that django-compressor uses the same path for its finder and output. The best solution I found is as follows.
Creating a custom finder
First, we create a custom search based on the new setting that COMPRESS_SOURCE_ROOT calls
from compressor.storage import CompressorFileStorage from compressor.finders import CompressorFinder from compressor.conf import settings class CompressorFileAltStorage(CompressorFileStorage): """ This alternative django-compressor storage class is utilised specifically for CompressorAltFinder which allows an independent find path. The default for ``location`` is ``COMPRESS_SOURCE_ROOT``. """ def __init__(self, location=None, base_url=None, *args, **kwargs): if location is None: location = settings.COMPRESS_SOURCE_ROOT
Using this new search
Just add this crawler to the STATICFILES_FINDERS setting in addition to the regular "compressor .finders.CompressorFinder"
eg.
STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 'mycomp.CompressorAltFinder', 'compressor.finders.CompressorFinder', )
And now configure the new parameter COMPRESS_SOURCE_ROOT
eg.
COMPRESS_SOURCE_ROOT = os.path.join(APP_DIR, 'assets')
I also set my STATIC_ROOT
STATIC_ROOT = os.path.join(APP_DIR, 'static-prod')
Testing solutions in development
I specifically tested compiling the LESS source code
(django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ tree app/assets app/assets βββ coffee β βββ script.coffee βββ less βββ import.less βββ style.less
With template tags
{% compress css %} <link rel="stylesheet" type="text/less" href="{{ STATIC_URL }}less/style.less" /> {% endcompress %}
This is read from the asset directory successfully and updated when files change.
The output is placed in the static-prod directory:
(django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ tree app/static-prod/ app/static-prod/ βββ CACHE βββ css β βββ style.5abda32cfef7.css β βββ style.6ca1a3d99280.css βββ js βββ script.8cb4f955df19.js 3 directories, 3 files
Testing Production Solutions
For your reference, here is what my static directory looks like
(django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ tree app/static app/static βββ hello.txt βββ photo.jpg 0 directories, 2 files
So let's go
(django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ rm -rf app/static-prod (django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ ./manage.py collectstatic --noinput Copying '/home/fots/django_learning/app/static/photo.jpg' Copying '/home/fots/django_learning/app/static/hello.txt' 2 static files copied. (django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ ./manage.py compress Found 'compress' tags in: /home/fots/django_learning/app/templates/layout.html Compressing... done Compressed 2 block(s) from 1 template(s). (django-cpython)fots@fotsies-ubprecise-01:~/django_learning$ tree app/static-prod app/static-prod βββ CACHE β βββ css β β βββ 5abda32cfef7.css β βββ js β β βββ 3b9d1c08d2c5.js β βββ manifest.json βββ hello.txt βββ photo.jpg 3 directories, 5 files
Then I started the web server as follows and confirmed that the site is working
./manage.py runserver 0.0.0.0:8000
Hope this helps someone out there :)