Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-compressor compiles SCSS files in STATIC_ROOT/app instead of app/static

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')
like image 650
mstringer Avatar asked Nov 09 '22 23:11

mstringer


1 Answers

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)

like image 115
tutuDajuju Avatar answered Nov 14 '22 23:11

tutuDajuju