Django管道不压缩或编译SCS

时间:2019-05-12 16:49:08

标签: sass django-staticfiles django-pipeline

我已经使用instructions on readthedocs安装了django-pipeline。但是,当我运行python manage.py collectstatic将SCSS压缩并编译为CSS时,会出现两个问题:

1. The name of the resulting static directory is `staticfiles`, not `static` as I expected, based on my `STATIC_ROOT` setting.
2. The contents of `staticfiles` are neither compressed nor compiled.

我的settings.py文件如下:

INSTALLED_APPS = [
    ...
    'django.contrib.staticfiles',
    'pipeline',
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

PIPELINE = {
    'PIPELINE_ENABLED': True,
    'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor',
    'JS_COMPRESSOR': 'pipeline.compressors.jsmin.JSMinCompressor',
    'STYLESHEETS': {
        'locallibrary': {
            'source_filenames': (
                'scss/styles.scss',
            ),
            'output_filename': 'css/styles.min.css',
        },
    },
    'COMPILERS': (
        'pipeline.compilers.sass.SASSCompiler',
    )
}

我的requirements.txt如下:

cssmin==0.2.0
dj-database-url==0.5.0
Django==2.2
django-appconf==1.0.3
django-crispy-forms==1.7.2
django-heroku==0.3.1
django-pipeline==1.6.14
gunicorn==19.9.0
jsmin==2.2.2
psycopg2==2.8.2
pytz==2019.1
rcssmin==1.0.6
rjsmin==1.0.12
six==1.12.0
sqlparse==0.3.0
whitenoise==4.1.2

我的目录结构是这样:

catalog (an app)
  |--static
     |--scss
        styles.scss
  |--templates
  various app files
locallibrary
  |--settings.py
  various project files
manage.py
...

是否与未设置SASS_BINARY有关?如果是这样,有人可以解释一下这是什么,我需要如何更改其默认设置?

运行python manage.py collectstatic后的预期结果:在名为static的目录中与manage.py处于同一级别的目录中压缩和编译的SCSS。

实际结果:名为staticfiles的目录与manage.py位于同一级别,如下所示:

staticfiles
  |--admin
  |--img
  |--scss
    |-- unminified/uncompressed scss files
  staticfiles.json

在此先感谢您的帮助!

0 个答案:

没有答案