用于将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

^{pr2}$

配置

您可以通过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和{}, 然后将编译该文件夹中的所有“普通”SCSS文件。 如果还使用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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
为@Nonnull注释参数编写java单元测试   对于JAVA,如何从它自己的类调用插入排序来将数组分类到一个单独的类中?   Java中嵌套SQL查询的字符串解析   java在所有带有特定注释的方法上调用带注释的方面   在Java中将base64转换为PDF   无法在Android上强制转换java getApplicationContext()   雅加达ee Java ee:如何获取我的应用程序的URL?   IntelliJ:如何导入的文件夹。java文件作为库?   多线程Java(FX)在播放一种声音的同时,播放另一种声音   网络爬虫我需要将proto3版本中protobuf生成的java代码添加到nutch 1.7中   使用JAXRS注释资源的java Restlet客户端   java如何查找给定月份的日期范围   java Minecraft Bukkit插件:我的小游戏传送机不工作   Java Excel搜索和数组列表工作不正常