使用django压缩和sass文件

时间:2018-09-26 12:33:23

标签: django sass

我已经成功配置django_sass_processor来生成scss文件并将其链接到一个主css文件。但是因为我还需要从其他几个文件中生成一个主要的JS文件,所以我想切换到django_compress,据我所知,它对于css / sass和JS也同样起作用。

但是不幸的是,我不明白如何配置compress来编译scss文件。我是否需要添加一个额外的预编译器,例如django-static-precompiler

目前,我已按如下所示进行设置压缩:

INSTALLED_APPS = [
    ...
    'compressor',
]

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_PRECOMPILERS = (
    ('text/x-sass', 'sass --scss "{infile}" "{outfile}"'),
    ('text/x-scss', 'sass --scss "{infile}" "{outfile}"'),
)

在我放入的测试模板中

{% load compress %}
{% compress css %}
<link href="app/styles/main.scss" rel="stylesheet" type="text/x-scss" />
{% endcompress %}

但是压缩甚至无法找到文件。我得到了错误

'app/styles/main.scss' isn't accessible via COMPRESS_URL ('/static/') and can't be compressed

app/styles/main.scss实际上是文件夹project/app/static/app/styles/main.scss的路径

不幸的是,在压缩文档中,除了COMPRESS_PRECOMPILERS

的设置之外,我对sass编译的了解不多。

0 个答案:

没有答案
相关问题