跳转到主要内容

用于定义、下载和预处理外部静态文件的实用工具。

项目描述

Build Status codecov.io PyPI Status license

版权 (C) 2013-2020 Samuel Colvin

类似于bower,但使用Python,更简单,并具有一些更多功能。

grablib 可以

  • 从URL下载文件,包括从zip文件中选择性提取。

  • 创建 .grablib.lock,保留所有下载文件的哈希值,这意味着资产不会意外更改。

  • 使用 libsass 编译sass/scss/css。

  • 使用 jsmin 连接和压缩javascript。

定义文件可以是JSON或YAML(见 示例)。

安装

grablib需要 python 3.6+

pip install grablib[build]

(您也可以使用 pip install grablib 来安装,无需构建需求,这在您不使用grablib进行构建时很有用,因为它避免了安装可能很慢的 jsminlibsass。)

CLI使用

这样定义您的静态文件:(grablib.yml

download_root: 'static/libs'
download:
  'https://code.jqueryjs.cn/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: true
build_root: 'static/prod'
build:
  # delete the entire static/prod directory before building, this is required for sass,
  # and generally safer
  wipe: '.*'
  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

from grablib import Grab

grab = Grab('path/to/definitions.json|yml')
grab.download()
grab.build()

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

grablib-0.8.tar.gz (14.3 kB 查看哈希值)

上传时间:

构建分布

grablib-0.8-py3-none-any.whl (14.8 kB 查看哈希值)

上传时间: Python 3