tsantsa:setuptools的css、js缩小和scss编译命令

tsantsa的Python项目详细描述


tsantsa提供setuptools命令,用于缩小css和js资源,以及 使用cssminslimitscss将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.jsstatic/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报告问题。

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

推荐PyPI第三方库


热门话题
Java中的开源字典组件   即使在成功执行删除查询之后,java更新的列表也不会显示在jsp页面中   java Apache:无法启动上下文路径/网站上的失败应用程序   java验证CSV中的特定列   对于具有专用内存的java应用程序,最小堆大小低于最大堆大小有意义吗?   java将数组中的值转换为多维数组   java在给定程序中,垃圾收集器在对象被取消引用之前正在运行。。。使用jre 7(32位)   java在运行时动态刷新文件夹   eclipse如何解决“java.net.BindException:地址已在使用:JVM_Bind”错误?   Java数组与数组   每次任务完成任务时,Java多线程都会安排任务   java部分编译时使用maven编织第三方jar   java Dokku单一回购中的多个应用程序   用apachevelocity生成javac/C++语言文件   java如何使用spring应用程序上下文中的属性文件实例化列表   java访问智能卡文件结构   具有GlobalMethodSecurity的java自定义UserDetailService循环引用   java如何集成Spring和JSF