用于定义然后下载和预处理外部静态文件的实用程序。
grablib的Python项目详细描述
版权所有(c)2013-2017 Samuel Colvin
有点像bower,但是在python中,更简单,并且有更多的特性。
grablib可以:
- 从url下载文件,包括有选择地从zip文件中提取。
- 创建.grablib.lock,它保留所有下载文件的哈希值,这意味着资产不能意外更改。
- 使用libsass编译sass/scss/css。
- 使用jsmin连接和缩小javascript。
定义文件可以是json或yaml(请参见examples)。
安装
grablib需要python 3.6+。
pip install grablib[build]
(您也可以简单地使用pip install grablib来安装,而不需要构建需求, 这在不使用grablib进行构建时非常有用,因为它避免了安装 jsmin和libsass,这可能比较慢。)
cli用法
这样定义静态文件:(grablib.yml)
download_root:'static/libs'download:'http://code.jquery.com/jquery-1.11.3.js':'js/jquery.js''https://github.com/twbs/bootstrap-sass/archive/v3.3.6.zip':'bootstrap-sass-3.3.6/assets/(.+)$':'bootstrap-sass/''GITHUB/codemirror/CodeMirror/5.8.0/lib/codemirror.js':'codemirror/'# simple scss file to import and compile bootstrap from above,# generally this would be in your code# this file just reads "@import 'bootstrap-sass/stylesheets/bootstrap';"'https://git.io/v1Z5J':'build_bootstrap.scss'debug:truebuild_root:'static/prod'build:# delete the entire static/prod directory before building, this is required for sass,# and generally saferwipe:'.*'cat:# concatenate jquery and codemirror into "libraries.js"# it won't get minified as debug is true, but without that it would'libraries.js':-'DL/js/jquery.js'-'DL/codemirror/codemirror.js'sass:# compile all css, scss and sass files which don't start with _ from the "download_root"# into the "css" directory, here that will just be build_bootstrap.scss which will# build the whole of bootstrap.# debug: true means you'll get map files and a copy of sass files so maps work properly.'css':'DL/'
然后下载并构建静态文件,只需:
grablib
库使用
您还可以从python调用grablib:
fromgrablibimportGrabgrab=Grab('path/to/definitions.json|yml')grab.download()grab.build()