让 django-pipeline 和 bower 一起玩得很好
getting django-pipeline and bower to play nicely together
我正在将 Bower 组件安装到我项目根目录下的 external/bower_components/
。我在 static
下有其他静态文件以及一些属于已安装应用程序的一部分。我正在尝试使用 django-pipeline 缩小所有存在于 bower_components
中的静态文件,而我单独留下其他静态文件。
我的问题是我不知道如何使用 django-pipeline 来缩小我的 Bower 组件,同时又不将所有 Bower 包复制到目标目录。
在settings.py
中:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
os.path.join(os.path.dirname(__file__), '..', 'external'),
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE = True
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
当我 运行 python manage.py collectstatic
时,我最终得到了 staticfiles
中我想要的所有东西(静态基础中的东西以及那些东西的缩小版本从 bower 拉进来),加上 bower 中每个包的完整来源。这从最终用户的角度来看是可行的,但其中有很多我实际上并不想要的多余垃圾。
为了解决这个问题,我尝试了 python manage.py collectstatic -i bower_components
。但是在这种情况下,忽略不仅导致 collectstatic
没有将文件复制过来,而且还导致 django-pipeline 看不到文件,最终导致
如果我尝试使用像 pipeline.finders.FileSystemFinder
这样的自定义管道查找器,它会导致 collectstatic
忽略所有静态脚本和 css 我想要的 django.contrib.admin
和我的 static/
文件夹。
有没有办法让我的蛋糕也吃到饱,让collectstatic
的copy功能关注一组,而django-pipeline的combination/minification关注一组不同的组?
写完之后我意识到答案可能是使用 PIPELINE_CSS
和 PIPELINE_JS
显式收集和缩小我安装的应用程序中的所有脚本和 css 但这似乎不非常理想,因为每次集成新应用程序时都会产生不寻常的开销。
是的,但是您需要修改静态查找器以将静态查找器更改为使用 django-pipeline 查找器:
STATICFILES_FINDERS = (
'pipeline.finders.FileSystemFinder',
'pipeline.finders.AppDirectoriesFinder',
'pipeline.finders.CachedFileFinder',
'pipeline.finders.PipelineFinder'
)
这应该只复制相关文件。
我正在将 Bower 组件安装到我项目根目录下的 external/bower_components/
。我在 static
下有其他静态文件以及一些属于已安装应用程序的一部分。我正在尝试使用 django-pipeline 缩小所有存在于 bower_components
中的静态文件,而我单独留下其他静态文件。
我的问题是我不知道如何使用 django-pipeline 来缩小我的 Bower 组件,同时又不将所有 Bower 包复制到目标目录。
在settings.py
中:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
os.path.join(os.path.dirname(__file__), '..', 'external'),
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE = True
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
当我 运行 python manage.py collectstatic
时,我最终得到了 staticfiles
中我想要的所有东西(静态基础中的东西以及那些东西的缩小版本从 bower 拉进来),加上 bower 中每个包的完整来源。这从最终用户的角度来看是可行的,但其中有很多我实际上并不想要的多余垃圾。
为了解决这个问题,我尝试了 python manage.py collectstatic -i bower_components
。但是在这种情况下,忽略不仅导致 collectstatic
没有将文件复制过来,而且还导致 django-pipeline 看不到文件,最终导致
如果我尝试使用像 pipeline.finders.FileSystemFinder
这样的自定义管道查找器,它会导致 collectstatic
忽略所有静态脚本和 css 我想要的 django.contrib.admin
和我的 static/
文件夹。
有没有办法让我的蛋糕也吃到饱,让collectstatic
的copy功能关注一组,而django-pipeline的combination/minification关注一组不同的组?
写完之后我意识到答案可能是使用 PIPELINE_CSS
和 PIPELINE_JS
显式收集和缩小我安装的应用程序中的所有脚本和 css 但这似乎不非常理想,因为每次集成新应用程序时都会产生不寻常的开销。
是的,但是您需要修改静态查找器以将静态查找器更改为使用 django-pipeline 查找器:
STATICFILES_FINDERS = (
'pipeline.finders.FileSystemFinder',
'pipeline.finders.AppDirectoriesFinder',
'pipeline.finders.CachedFileFinder',
'pipeline.finders.PipelineFinder'
)
这应该只复制相关文件。