跳转到主要内容

一个用于将SCSS文件编译为CSS的命令行界面和相关的预提交钩子。

项目描述

scss-compile

一个用于将SCSS文件编译为CSS的命令行界面和相关的预提交钩子。

此CLI是围绕libsass-python的一个小型包装器,它也旨在与pre-commit兼容,并提供一个预提交钩子。

注意: 此包处于alpha版本,但看起来工作如预期,将在sphinx-panelssphinx-book-theme中试用。

安装

直接作为CLI使用

pip install scss-compile
scss-compile --help

通过pre-commit使用

添加到您的.pre-commit-config.yaml

-   repo: https://github.com/executablebooks/scss-compile
    rev: v0.1.0
    hooks:
      - id: scss-compile
        args: [--config=config.yml] # optional

配置

您可以直接通过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 = 5
sourcemap = true
hash_filenames = true
output_format = "compressed"
partial_depth = 1
translate = ["tests/example_sass:tests/output_css"]

config.yml/config.yaml

scss-compile:
  precision: 5
  sourcemap: true
  hash_filenames: true
  output_format: compressed
  partial_depth: 1
  translate: ["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

如果您指定了部分文件,例如以 _ 开头的文件,通过 @import@use 使用,则该文件夹中的所有“常规”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 tox
tox -e py37

测试 CLI

tox -e py37-cli

代码风格

pip install pre-commit
pre-commit run --all

项目详情


下载文件

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

源分布

scss-compile-0.1.3.tar.gz (7.5 kB 查看散列)

上传时间

构建分布

scss_compile-0.1.3-py3-none-any.whl (7.6 kB 查看散列)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面