Reputation: 2302
We're using django-compressor
and the django.contrib.staticfiles
app and we're having problems while running the django development server and working on our SCSS: the wrong SCSS files gets compiled. The versions that are in STATIC_ROOT/app
are getting found rather than the versions in app/static. This makes it so that edits to SCSS in app/static
aren't reflected in the compiled CSS.
Removing everything in STATIC_ROOT/app
fixes the issue, but it causes much confusion if collectstatic
is executed for some reason.
Is there a way to ensure that the app/static files are compiled rather than any existing STATIC_ROOT/app files?
We're using django-compressor 1.4 with django 1.6 and the following settings are used in the django settings file:
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
'compressor.finders.CompressorFinder',
)
COMPRESS_PRECOMPILERS = (
("text/x-scss", 'sass --scss'),
)
STATICFILES_DIRS = [] #default
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
Upvotes: 6
Views: 2933
Reputation: 16666
Use django-libsass
:
COMPRESS_PRECOMPILERS = (
('text/x-sass', 'django_libsass.SassCompiler'),
('text/x-scss', 'django_libsass.SassCompiler'),
)
https://github.com/torchbox/django-libsass
Make sure to configure STATIC_URL
and STATIC_ROOT
correctly as described in https://docs.djangoproject.com/en/1.8/howto/static-files/.
For example:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
Compressor will take care of the rest, appropriately depending on the DEBUG
variable.
Upvotes: 0
Reputation: 10850
Your sass --scss
comand in COMPRESS_PRECOMPILERS
does not explicitly state a target directory. Hence the default is used, which seems to be stdin
and stdout
.
Now, compressor documentation is not so clear what using stdout
means; but, from the examples it seems the files will end up in COMPRESS_ROOT (defaults to STATIC_ROOT/CACHE
which in your case is root/base/static/CACHE/
)
What I personally like is to explicitly state the in/out directories (to remain constant in different environments). Here is an example (using a pyScss compiler, but the idea is the same):
scss_cmd = '{python} -mscss -A "{image_output_path}" -a "{static_url}" ' \
'-S "{static_root}" -o "{{outfile}}" "{{infile}}"'.format(
python=sys.executable,
image_output_path=COMPRESS_ROOT,
static_url=STATIC_URL,
static_root=os.path.join(PROJECT_ROOT),
)
COMPRESS_PRECOMPILERS = (
('text/x-scss', scss_cmd),
)
(sorry if digging up long forgotten issues)
Upvotes: 1