tsantsa:setuptools的css、js缩小和scss编译命令
tsantsa的Python项目详细描述
tsantsa提供setuptools命令,用于缩小css和js资源,以及 使用cssmin、slimit和scss将scss资源编译为css。
scss、cssmin和slimit是纯python包,不需要任何外部命令。
此包装的灵感来源于并基于Sylvain Prat使用 YUI compressor来自雅虎!股份有限公司
安装tsantsa时,有三个新命令可用:
- tsantsa_js用于缩小javascript文件
- tsantsa_css用于缩小css文件
- compile_scss将scss文件编译为css
有关这些命令的详细信息,请参见Usage部分。
安装
< TSANSA命令意在在现有的Python项目中使用。所以,在 为了使命令在项目中可用,只需将tsantsa添加到 项目的要求,例如:setup( ... install_requires=['tsantsa'], ... )
然后,当您安装软件包时,tsantsa命令将可用。
用法
tsantsa提供用于缩小css和js资源以及编译scs的命令 资源:
- tsantsa_js用于缩小javascript文件
- tsantsa_css用于缩小css文件
- compile_scss将scss文件编译为css
缩小javascript文件
要显示tsantsa_js命令的选项,只需键入:
$ python setup.py tsantsa_js --help
您应该获得如下信息:
Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the package Global options: --verbose (-v) run verbosely (default) --quiet (-q) run quietly (turns verbosity off) --dry-run (-n) don't actually do anything --help (-h) show detailed help message --no-user-cfg ignore pydistutils.cfg in your home directory Options for 'tsantsa_js' command: --sources sources files --output minified output filename. If you provide a template output filename (e.g. "static/%s-min.ext"), the source files will be minified individually --mangle mangle names usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help
可以在命令行上使用tsantsa_js工具。下面是一个示例:
$ python setup.py tsantsa_js --sources static/*.js --output static/combined.js
但是,使用tsantsa_js最有用的方法是通过setup.cfg文件 位于项目根目录中(即,在^{tt13}旁边$ 文件:
[tsantsa_js] sources = static/one.js static/two.js output = static/combined.js mangle = yes
然后,运行tsantsa_js命令,将读取命令选项 从setup.cfg文件中添加命令行参数。
注意,由于对于许多源有一个输出文件,所以 源文件合并到一个压缩为 生成单个缩小文件。
但是,您可能需要单独压缩源文件并获取 不同的缩小文件。在这种情况下,您应该提供一个模板输出 文件名,而不是常规输出文件名。模板输出文件名是 文件名,其中有一个%s,将由当前源替换 正在处理的名称。例如:
[tsantsa_js] sources = static/one.js static/two.js output = static/%s-min.js
运行python setup.py tsantsa_js将生成两个缩小的文件: static/one-min.js和static/two-min.js。
缩小css文件
您还可以通过键入:
$ python setup.py tsantsa_css --help
结果如下:
Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the package Global options: --verbose (-v) run verbosely (default) --quiet (-q) run quietly (turns verbosity off) --dry-run (-n) don't actually do anything --help (-h) show detailed help message --no-user-cfg ignore pydistutils.cfg in your home directory Options for 'tsantsa_css' command: --sources sources files --output minified output filename. If you provide a template output filename (e.g. "static/%s-min.ext"), the source files will be minified individually usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help
此命令的使用方法与tsantsa_js命令的使用方法大致相同,但是 它有更少的选择。
组合缩小操作
由于内置的^{tt22},您还可以组合缩小操作$ 命令(仍在setup.cfg文件中指定,但不能用于纯distutils):
[alias] minify_each_css = tsantsa_css --sources static/*.css --output static/%s-min.css minify_each_js = tsantsa_js --sources static/*.js --output static/%s-min.js minify_each = minify_each_css minify_each_js
然后键入:
$ python setup.py minify_each
编译scss文件
您还可以通过键入:
$ python setup.py compile_scss --help
结果如下:
Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the package Global options: --verbose (-v) run verbosely (default) --quiet (-q) run quietly (turns verbosity off) --dry-run (-n) don't actually do anything --help (-h) show detailed help message --no-user-cfg ignore pydistutils.cfg in your home directory Options for 'compile_scss' command: --sources sources files --output compiled css output file usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help
支架
此项目位于Github上。 请通过Bug Tracker报告问题。