"sass.CompileError: Error: It's not clear which file to import" arising when using Django Compressor and Django Sass Processor

"sass.CompileError: Error: It's not clear which file to import" arising when using Django Compressor and Django Sass Processor

我正在尝试将 Materialise 源添加到 Django 项目中。在我的 stylesheets 目录中,我有以下结构:

(venv) Kurts-MacBook-Pro-2:lucy kurtpeek$ tree lucy-web/lucy_web/static/stylesheets
lucy-web/lucy_web/static/stylesheets
├── mixins.scss
├── terms_of_use.scss
└── vendor
    ├── components
    │   ├── _badges.scss
    │   ├── _buttons.scss
    │   ├── _cards.scss
    │   ├── _carousel.scss
    │   ├── _chips.scss
    │   ├── _collapsible.scss
    │   ├── _color-classes.scss
    │   ├── _color-variables.scss
    │   ├── _datepicker.scss
    │   ├── _dropdown.scss
    │   ├── _global.scss
    │   ├── _grid.scss
    │   ├── _icons-material-design.scss
    │   ├── _materialbox.scss
    │   ├── _modal.scss
    │   ├── _navbar.scss
    │   ├── _normalize.scss
    │   ├── _preloader.scss
    │   ├── _pulse.scss
    │   ├── _sidenav.scss
    │   ├── _slider.scss
    │   ├── _table_of_contents.scss
    │   ├── _tabs.scss
    │   ├── _tapTarget.scss
    │   ├── _timepicker.scss
    │   ├── _toast.scss
    │   ├── _tooltip.scss
    │   ├── _transitions.scss
    │   ├── _typography.scss
    │   ├── _variables.scss
    │   ├── _waves.scss
    │   └── forms
    │       ├── _checkboxes.scss
    │       ├── _file-input.scss
    │       ├── _forms.scss
    │       ├── _input-fields.scss
    │       ├── _radio-buttons.scss
    │       ├── _range.scss
    │       ├── _select.scss
    │       └── _switches.scss
    ├── materialize_v1.scss

其中 materialize_v1.scsscomponents 是从 http://materializecss.com/getting-started.html 提供的源版本下载的;我已将 materialize.scss 重命名为 materialize_v1.scss 以避免与旧版本的名称冲突。

terms_of_use.scss中,我导入materialize如下:

@import "vendor/materialize_v1";    // Materialize v1.0.0beta

在模板中,我使用 compresssass_src 标签如下:

{% load compress %}
{% load sass_tags %}

<html>
  <head>
    {% compress css %}
    <link href="{% sass_src 'stylesheets/vendor/materialize_v1.scss' %}" rel="stylesheet" type="text/css" />
    <link href="{% sass_src 'stylesheets/terms_of_use.scss' %}" rel="stylesheet" type="text/css" />
    {% endcompress %}

在我处于开发模式的本地机器上(DEBUG = True),一切似乎都运行良好。但是,当我尝试部署到 Heroku 时,出现以下错误:

(venv) Kurts-MacBook-Pro-2:lucy kurtpeek$ git push staging `git subtree split --prefix lucy-web terms-of-service`:master --force
cache for 09dc1ce7e3b490f30ceeabbca0c9375e2013b596 already exists!
Counting objects: 4188, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1430/1430), done.
Writing objects: 100% (4188/4188), 1.22 MiB | 938.00 KiB/s, done.
Total 4188 (delta 3084), reused 3590 (delta 2687)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:        Obtaining django_airbrake from git+https://github.com/airbrake/airbrake-django.git@02b0b422c6cdc8d5727bd6ea045bfdc362b380cd#egg=django_airbrake (from -r /tmp/build_64226978df3aac094d9ae50e59da9e58/requirements.txt (line 9))
remote:          Cloning https://github.com/airbrake/airbrake-django.git (to 02b0b422c6cdc8d5727bd6ea045bfdc362b380cd) to /app/.heroku/src/django-airbrake
remote:          Could not find a tag or branch '02b0b422c6cdc8d5727bd6ea045bfdc362b380cd', assuming commit.
remote:        Installing collected packages: django-airbrake
remote:          Found existing installation: django-airbrake 0.0.2
remote:          Running setup.py develop for django-airbrake
remote:        Successfully installed django-airbrake
remote: 
remote: -----> Running post-compile hook
remote: -----> $ python manage.py compilescss
remote:        ................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Traceback (most recent call last):
remote:          File "manage.py", line 29, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/sass_processor/management/commands/compilescss.py", line 160, in handle
remote:            self.parse_template(template_name)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/sass_processor/management/commands/compilescss.py", line 271, in parse_template
remote:            self.compile_sass(sass_filename, node.path)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/sass_processor/management/commands/compilescss.py", line 289, in compile_sass
remote:            content = sass.compile(**compile_kwargs)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/sass.py", line 640, in compile
remote:            raise CompileError(v)
remote:        sass.CompileError: Error: It's not clear which file to import for '@import "vendor/materialize_v1"'.
remote:               Candidates:
remote:                 vendor/materialize_v1.scss
remote:                 vendor/materialize_v1.css
remote:               Please delete or rename all but one of these files.
remote:                on line 1 of lucy_web/static/stylesheets/terms_of_use.scss
remote:        >> @import "vendor/materialize_v1";    // Materialize v1.0.0beta
remote:           ^
remote:        
remote: 
remote:  !     Error while running '$ python manage.py compilescss'.
remote:        See traceback above for details.
remote: 
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to lucy-staging.
remote: 
To https://git.heroku.com/lucy-staging.git
 ! [remote rejected]   34560aaa9267f49d1e6042390e203efe9d275def -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/lucy-staging.git'

似乎 compilescss 命令首先将 materialize_v1.scss 编译成 materialize_v1.css,之后它变得模棱两可,当我 @import 它在 terms_of_use.scss.

这听起来像是正在发生的事情吗?我怎样才能消除歧义?

您应该将 vendor/materialize_v1.scss 重命名为 vendor/_materialize_v1.scss。这可以防止编译旨在包含到其他 scss 文件中的文件。

此外,从 HTML 引用 vendor/materialize_v1.scss 并随后将该文件第二次包含到 stylesheets/terms_of_use.scss 中是没有意义的。因此,最好的方法是也删除 HTML 中的第一个引用,即。 <link href="{% sass_src 'stylesheets/vendor/materialize_v1.scss' %}" rel="stylesheet" type="text/css" /> 并且完全依赖于 stylesheets/terms_of_use.scss.

中的 @import 语句