I'm not sure I'm doing things right, but here's the issue:
django-compressor
with the lessc
preprocessorCOMPRESS_ENABLED
is True
, all is working fineCOMPRESS_ENABLED
is False
, the CssAbsoluteFilter
is not running anymore, which means all relative image URLs are kept relative and are therefore broken (since they're not relative from the CACHE
directory)I could come up with a "clever" directory structure where relative paths resolve to the same file whether they originate from the CACHE
directory or from the LESS files directory, but that seems like a brittle workaround.
How do you usually work when it comes to LESS + django-compressor
?
You can use a simple workaround:
COMPRESS_PRECOMPILERS = (
('text/less', 'path.to.precompilers.LessFilter'),
)
precompilers.py:
from compressor.filters.base import CompilerFilter
from compressor.filters.css_default import CssAbsoluteFilter
class LessFilter(CompilerFilter):
def __init__(self, content, attrs, **kwargs):
super(LessFilter, self).__init__(content, command='lessc {infile} {outfile}', **kwargs)
def input(self, **kwargs):
content = super(LessFilter, self).input(**kwargs)
return CssAbsoluteFilter(content).input(**kwargs)
Please note this works with both COMPRESS_ENABLED = True
and False
.
This has been fixed in django-compressor 1.6. From the changelog:
Apply CssAbsoluteFilter to precompiled css even when compression is disabled
i.e. the absolute filter is run on your less files even with DEBUG = True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With