【问题标题】:Strange Issue When Minifying CSS via django-pipeline通过 django-pipeline 缩小 CSS 时出现的奇怪问题
【发布时间】:2013-10-25 17:33:38
【问题描述】:

我正在使用 django-pipeline 来缩小我的 CSS。在我使用 PipelineCachedStorage 之前,一切都会正确缩小,这样我就可以获得版本化的缓存破坏文件名。我收到以下错误:

ValueError: The file 'img/glyphicons-halflings.png' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x19069d0>

我已经对我的项目中的所有文件进行了 grep,并发现这个 PNG 在 bootstrap.css 中,但我没有包含要缩小的那个文件。这是我的 django-pipeline 特定设置:

PIPELINE_CSS = {
    'ab': {
        'source_filenames': (
            'main.css',
            'segment-animation.css',
            ),
        'output_filename' : 'ab.css',
        }
}

PIPELINE_YUGLIFY_BINARY = '/home/redacted/ts/redacted/node_modules/yuglify/bin/yuglify'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

提前致谢!

编辑:

管道的新设置:

PIPELINE_COMPILERS = (
  'pipeline.compilers.less.LessCompiler',
)

PIPELINE_CSS = {
    'ab': {
        'source_filenames': (
            'bootstrap-less/bootstrap.less',
            'main.css',
            'segment-animation.css',
            ),
    'output_filename' : 'ab.css',
        }
}

PIPELINE_YUGLIFY_BINARY = '/home/redacted/ts/redacted/node_modules/yuglify/bin/yuglify'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

【问题讨论】:

    标签: django django-pipeline yuglify


    【解决方案1】:

    该错误与 Pipeline 并不完全相关,而是与 PipelineCachedStorage 扩展的 Django 的 CachedStaticFilesStorage 相关。缓存的存储将在您的 css 文件中查找文件引用,并将 url('asset-link')@import 'resource-link' 替换为指向附加了 md5 哈希的版本的适当链接。

    这会将url('img/glyphicons-halflings.png') 变成url('img/glyphicons-halflings.&lt;hash&gt;.png')。因此,如果您的 css 文件中有资产引用但没有基础资产,则 CachedStaticFilesStoragepost_process() 将抛出该错误。

    您可以阅读更多here。我建议使用 django 管道编译较少版本的引导程序,并删除您不需要的较少组件,例如如果您不想包含引导程序图标的图标。或者您可以包含适当的资产。

    【讨论】:

    • “更少版本的引导程序”是什么意思?你的意思是 bootstrap.min.css 而不是 bootstrap.css?
    • github.com/twbs/bootstrap/tree/master/less 您也可以使用 django-pipeline 将 less 编译成 css。或者,您可以通过 bootstrap.css 并删除违规行。
    • 啊,对了,明白了。当我回到我的电脑后面时,我会试一试,让你知道它是怎么回事。谢谢!!
    • 我已经取得了一些进展(安装了 ruby​​、lessc 等),但我遇到了另一个错误:IOError: [Errno 2] No such file or directory: u'/home/redacted/ts/redacted/redacted/assets/bootstrap-less/bootstrap.css'。为什么要寻找那个文件?它在 bootstrap.less 包中不存在,也没有在任何地方指定。我在原始帖子中发布了我对设置文件的添加。
    • collectstatic 期间是否出现此错误?还是在开发服务器中?
    【解决方案2】:

    我发现django-pipeline-forgiving 包用 Django CachedStaticFilesStorage / PipelineCachedStorage 很好地解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-26
      • 2015-08-06
      • 2010-10-16
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多