-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COMPRESS_PRECOMPILERS break css url() #226
Comments
I'm not sure I understand correctly, can you provide a test case showing the problem? |
I have a scss precompiler for my scss files. It has to be executed even in development since the browser can't handle scss files.
As a result I get a precompiled css for each scss file. So far so good. however, the problem occurs when I reference images with My config looks like this:
this works:
this does not:
|
Yes, this is an issue (at least, I have the same problem). I'm using twitter bootstrap as a css framework. That contains less stylesheets and I handle those with compressor. But the sprite file with icons that's included in twitter bootstrap is missing when setting COMPRESS_ENABLED=False (as I'm developing) because the icon .png file isn't moved to the CACHE/ directory. |
It would be a solution to serve all static content from the CACHE location while DEBUG=True. |
Well, for the record, that's why the |
CssAbsoluteFilter does not run when COMPRESS_ENABLED = False. In my use case I want to run the precompressor and the CssAbsoluteFilter, but I don't want to compress the css. Is it possible to use CssAbsoluteFilter without compressing the css? |
It's not possible right now, no. |
I've encountered this issue as well, and it makes development a bit troublesome. Setting the COMPRESS_OUTPUT_DIR to an empty string might work, but only in simple cases; any sort of deeper directory structure breaks all of the url paths in CSS files, since the pre-compilers output to COMPRESS_OUTPUT_DIR/css regardless of source location. With so many css urls being relative, you're forced to turn compression on or abandon pre-compilers. One alternative I was brainstorming, was detecting in the file to be pre-compiled, whether or not compression is enabled and adjusting the image paths in that file...which would be an ugly hack if it was possible. |
Scratch my comment. It does still apply, but I think one of the pull requests (specific commit below), will allow for the CssAbsoluteFilter, thus avoiding the issue entirely. Nice. |
Setting COMPRESS_OUTPUT_DIR to an empty directory just removes CACHE from the resulting filename. So the file still ends up in the COMPRESS_ROOT. Setting COMPRESS_ROOT to the empty string places CACHE/css/... in the directory where you started django. So there's no way to currently get django-compressor to create the output file in the same directory as the source file. |
Same problem here, I think it is important |
My workaround for this was to add the following to the bottom of my settings: if not COMPRESS_ENABLED:
COMPRESS_ENABLED = True
COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter']
COMPRESS_JS_FILTERS = [] The settings are saying don't apply filters, but you want this one to apply anyway. You want some filters to get some sort of special status that makes them run whether or not |
I'm doing the same as @willhardy at the moment. It works, but as the compressor runs, the JS files also are concatenated and that makes the debugging a bit harder, as the resulting file can be quite long. It should be possible to run some filters even when COMPRESS_ENABLED = False. Or should the CssAbsoluteFilter be run as a precompiler, as it really doesn't do any compressing? The pull request #291 is somewhat related, as it would allow class-based precompilers. |
Sorry to leave a "me too" comment; but I too am doing the same as @willhardy. It would be nice not to have JS or CSS files concatenated while debugging; and it's also nice if SASS/SCSS/LESS files are compiled into something with a filename that indicates the source. |
+1 on this bug. Took me a while to understand this, but here is the problem.
The above attempts to reference this location: So, the above less gets precompiled and served from: Which ends up looking in the full path: So, this is actually a special case for css IMO. A CSS Absolute filter is an absolute requirement when it comes to precompilers only because of where a precompiled file is served from. This problem gets compounded with the current absolute filter. Trying to account for the
The above attempts to account for the extra Hopefully I've helped clear up any misunderstandings if there were any. |
I have just submitted a pull request to address this issue, which is a big one for me too. |
I just started using SCSS with Django Compressor and this is a big problem for me also. I'm using @willhardy's hack at the moment but it creates issues with when the value of COMPRESS_ENABLED is changed in a local settings file. |
Can the absolute URL filter just be implicit, and disabled by an optional setting? e.g. COMPRESS_CSS_ABSOLUTE_URL_FILTER = False in the rare instance someone wouldn't want this functionality. |
+1, having this issue myself as well |
I'm currently using a custom Css absolute filter + SCSS precompiler combination to get around this issue and it works without any problems. The main point here is that the CssAbsoluteFilter is used during precompilation, so I don't need to enable compression for it to work. This keeps the original SCSS/JS files separate and the names of the files are not obfuscated hashes, which makes for happier development :-) (The implementation is adapted from somone's LESS-based implementation, but I can't find it right now. Anyhow, the code is very easy to convert to LESS if that's your preprocessor choice.) In lib/scssabsolutefilter.py:
and in settings
Anyway, it would be nice if there was a way to do this correctly without any extra code. |
+1 for this issue and I'm not even using any LESS or SASS |
Also I'm on Amazon S3 so I cannot make a sim link like suggested at yourcelf/btb#20 |
Same issue here. django-cms, django-sekizai, django-compressor and pyscss. |
When the LESS files are served but compression is disabled, the relative URL between the generated CSS and other assets is wrong (using the default compressor settings). This fixes changes the output directory name to match the path of Oscar's assets, which fixes this issue. Related to django-compressor/django-compressor#226 Fixes django-oscar#649
Same issue here. CssAbsoluteFilter should be a compressor option, as @dustinfarris said (which could be implemented as a filter internally). You already know that compressor will generate a css in a different location than the original file, so it is very likely that your relative paths are going to break. When would you not want to fix your relative paths? |
Not elegant at all, but I solved this by creating a couple of symlinks. |
Is this still open, really? How do people develop locally using sass/less/scss? I believe this is a very important bug. |
I'm using a customer LessCompiler that runs the output through the CssAbsoluteFilter, similar to @anttihirvonen, and this works pretty well. Another solution is to use absolute urls in your LESS files, with a @static-url variable that matches django's STATIC_URL setting. You won't be needing CssAbsoluteFilter anymore, but this may not work if you are using S3. For example: |
+1, @anttihirvonen's solution works, but IMO it should be possible to do this through settings only. |
In case anyone is still stuck on this issue, I found that this worked for me: |
I've modified @anttihirvonen's solution to work with django-libsass (which uses the faster C implementation of SASS):
It would be nice, though, I've there wasn't such a workaround needed. And it took my quite a while to figure out what was going on and how to fix it. |
@woeye Having just stumbled across this problem myself, I propose to incorporate this workaround into django-libsass: torchbox/django-libsass#8 +1 for a general solution to this within django-compressor, though! |
With django-compressor 1.5: from compressor.filters.css_default import CssAbsoluteFilter
from django_libsass import SassCompiler
class PatchedSCSSCompiler(SassCompiler):
def input(self, **kwargs):
content = super(PatchedSCSSCompiler, self).input(**kwargs)
kwargs.setdefault('filename', self.filename)
return CssAbsoluteFilter(content).input(**kwargs) |
Thanks @jsSenanga I was just trying to track this issue down. Thanks @woeye for the original patch... |
+1 for a permanent solution. In my case, I've had the problem with django-libsass, and solved it by using @jsSenanga 's solution. Thank you! |
shoutout to @domoritz :) i thought it was really funny and random to see you here. (johannes linke speaking) |
Haha, awesome to meet you here @karyon and thanks for working on this issue. I don't quite remember what I was working on back then but it looks like a relevant issue judging from the number of people in this thread. |
Since the precompiled files are served from another location, relative links in css files do not work anymore.
The Problem can be solved by setting the output dir to an empty string.
However, it would be great to have processed urls in the css file that link to the right locations of images.
The text was updated successfully, but these errors were encountered: