用于将SCSS文件编译为CSS的CLI,以及相关的预提交挂钩。
scss-compile的Python项目详细描述
scss编译
用于将SCSS文件编译为CSS的CLI,以及相关的预提交钩子。
这个CLI是libsass-python的一个小包装, 它也旨在与pre-commit兼容, 并提供预提交钩子。
NOTE:该包在alpha版本中,但看起来工作正常, 将在sphinx-panels进行试验, 然后sphinx-book-theme。
安装
要直接用作CLI,请执行以下操作:
pip install scss-compilescss-compile --help
要通过预提交使用,请执行以下操作:
添加到您的.pre-commit-config.yaml
配置
您可以通过CLI或使用配置文件直接配置编译
(只需将-
替换为_
):
$ scss-compile --help Usage: scss-compile [OPTIONS] [PATHS]... Compile all SCSS files in the paths provided. For directories; include all non-partial SCSS files, and for files; if partial, include all adjacent, non-partial, SCSS files.Options: --recurse / --no-recurse For directories, include files in sub- folders. [default: True] -d, --partial-depth INTEGER For partial files (starting '_') include all SCSS files up 'n' parent folders [default: 0] -s, --stop-on-error Stop on the first compilation error. -e, --encoding TEXT [default: utf8] -f, --output-format [nested|expanded|compact|compressed] [default: compressed] -m, --sourcemap Output source map. -h, --hash-filenames Add the content hash to filenames: <filename><hash-prefix><hash>.css (old hashes will be removed). --hash-prefix TEXT Prefix to use for hashed filenames. [default: #] -t, --translate TEXT Source to output path translations, e.g. 'src/scss:dist/css' (can be used multiple times) -p, --precision INTEGER precision for numbers. [default: 5] -q, --quiet Remove stdout logging. -v, --verbose Increase stdout logging. --exit-code INTEGER Exit code when files changed. [default: 2] --no-git Do not add new files to a git index. --test-run Do not delete/create any files. --config FILE Read default configuration from a file (allowed extensions: .json, .toml, .yml, .yaml.) --help Show this message and exit.
--config
可以指向三种文件格式中的任何一种:
config.json
:
{"scss-compile":{"precision":5,"sourcemap":true,"hash_filenames":true,"output_format":"compressed","partial_depth":1,"translate":["tests/example_sass:tests/output_css"]}}
config.toml
:
[scss-compile]precision=5sourcemap=truehash_filenames=trueoutput_format="compressed"partial_depth=1translate=["tests/example_sass:tests/output_css"]
config.yml
/config.yaml
:
scss-compile:precision:5sourcemap:truehash_filenames:trueoutput_format:compressedpartial_depth:1translate:["tests/example_sass:tests/output_css"]
使用
如果您只需指定一个普通的SCSS文件,那么CSS文件将输出到同一个文件夹中:
$ scss-compile scss/file.scss
scss/
file.scss
file.css
如果使用sourcemap
选项,则还将输出一个sourcemap,
以及添加到CSS的sourceMappingURL
注释:
$ scss-compile scss/file.scss --sourcemap
scss/
file.scss
file.css
file.scss.map.json
如果使用hash_filenames
选项,那么CSS文件名将包括内容哈希(并且任何具有不同哈希的现有文件都将被删除):
$ scss-compile scss/file.scss -- hash-filenames
scss/
file.scss
file#beabd761a3703567b4ce06c9a6adde55.css
如果指定一个部分文件,即以_
开头的文件使用via@import
和{partial-depth
选项,则父文件夹中的文件也将被编译。
$ scss-compile scss/imports/_partial.scss -- partial-depth=1
scss
/imports
_partial.scss
file.scss
file.css
如果设置--translate
选项,则输出文件将被“转换”到指定的输出路径
(如果不存在,将创建它):
$ scss-compile scss/file.scss --translate "src/scss:dist/css" --sourcemap
src/scss/
file.scss
dist/css/
file.css
file.scss.map.json
如果指定一个目录,那么它将首先查找该目录中的所有SCSS文件,
和递归子文件夹(除非使用--no-recurse
),然后将每个单独的文件按上述方式处理。
发展
要运行测试:
pip install toxtox -e py37
要测试CLI,请执行以下操作:
tox -e py37-cli
对于代码样式:
pip install pre-commitpre-commit run --all
- 项目
标签: