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

We use the django-compressor and django.contrib.staticfiles application, and we have problems when starting the django development server and working with our SCSS: the wrong SCSS files were compiled. Versions found in STATIC_ROOT/app are obtained, not versions in the / static application. This ensures that changes to SCSS in app/static not reflected in compiled CSS.

Removing everything in STATIC_ROOT/app fixes the problem, but causes some confusion if collectstatic is executed for some reason.

Is there a way to make sure that the app / static files are compiled, and not any existing STATIC_ROOT / app files?

We are 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') 
+5
source share
2 answers

Your sass --scss in COMPRESS_PRECOMPILERS does not explicitly specify the destination directory. Therefore, the default value is used, which seems to be stdin and stdout .

Now the documentation for the compressor is not so clear, which means using stdout ; but, by examples, it seems that the files will be in COMPRESS_ROOT (by default STATIC_ROOT/CACHE , which in your case is root/base/static/CACHE/ )

I personally like to explicitly specify I / O directories (to remain constant in different environments). Here is an example (using the 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 you dig up long forgotten problems)

+1
source

Use django-libsass :

 COMPRESS_PRECOMPILERS = ( ('text/x-sass', 'django_libsass.SassCompiler'), ('text/x-scss', 'django_libsass.SassCompiler'), ) 

https://github.com/torchbox/django-libsass

Be sure to configure STATIC_URL and STATIC_ROOT correctly, as described in https://docs.djangoproject.com/en/1.8/howto/static-files/ .

For instance:

 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', ) 

The compressor takes care of the rest, respectively, depending on the DEBUG variable.

0
source

Source: https://habr.com/ru/post/1206309/


All Articles