Minify

Minify provides distutils commands for minifying CSS and JS resources
Download

Minify Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Sylvain Prat
  • Publisher web site:
  • http://bitbucket.org/sprat/

Minify Tags


Minify Description

Minify is a Python tool that provides distutils commands for minifying CSS and JS resources using the well-known YUI compressor from Yahoo! Inc. When you install minify, two new distutils commands are available:- minify_js which minifies Javascript files- minify_css which minifies CSS filesSee the Usage section for more information about these commands.InstallationThe Minify commands are meant to be used in an existing python project. So, in order to make the commands available in your project, just add minify to the requirements of your project, for example:setup( ... install_requires=, ...)Then, when you install your package (e.g. with python setup.py develop), the minify commands will be available.Since the YUI compressor tool is written in Java, you should have a Java virtual machine installed on your system and available in your system PATH.UsageMinify provides two commands for minifying CSS and JS resources:- minify_js which minifies Javascript files- minify_css which minifies CSS filesMinifying Javascript filesTo show the options of the minify_js command, just type: python setup.py minify_js --helpYou should obtain something like this:Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the packageGlobal 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 directoryOptions for 'minify_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 --charset Read the input file(s) using --line-break Insert a line break after the specified column number --nomunge Minify only, do not obfuscate --preserve-semi Preserve all semicolons --disable-optimizations Disable all micro optimizationsusage: setup.py cmd1 ...] or: setup.py --help or: setup.py --help-commands or: setup.py cmd --helpThe minify_js tool can be used on the command-line. Here is an example: python setup.py minify_js --sources static/*.js --output static/combined.jsBut, the most useful way to use minify_js is via a setup.cfg file located in your project root directory (that is, next to the setup.py file):sources = static/one.js static/two.jsoutput = static/combined.jsnomunge = yesThen, we you run the minify_js command, the command options will be read from the setup.cfg file in addition to the command-line arguments.Note that, since there's a single output file for many sources, the sources files are merged into a single file which is compressed with the YUI compressor in order to produce a single minified file.However, you may want to compress the sources files individually and obtain distinct minified files. In that case, you should provide a template output filename instead of a regular output filename. A template output filename is a filename with a %s in it, which will be substitued by the current source name being processed. For example:sources = static/one.js static/two.jsoutput = static/%s-min.jsRunning python setup.py minify_js will then produce two minified files: static/one-min.js and static/two-min.js.Minifying CSS filesYou can also see the options of the minify_css command, by typing: python setup.py minify_css --helpAnd here is the result:Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the packageGlobal 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 directoryOptions for 'minify_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 --charset Read the input file(s) using --line-break Insert a line break after the specified column numberusage: setup.py cmd1 ...] or: setup.py --help or: setup.py --help-commands or: setup.py cmd --helpThis command can be used about the same way as the minify_js command, but it has less options.Combining minification operationsYou can also combine minification operations thanks to the builtin alias command (still specified in the setup.cfg file):minify_each_css = minify_css --sources static/*.css --output static/%s-min.css --charset utf-8minify_each_js = minify_js --sources static/*.js --output static/%s-min.js --charset utf-8minify_each = minify_each_css minify_each_jsThen call minify_each by typing: python setup.py minify_eachSupportThis project is hosted on bitbucket.org. Please report issues via the bug tracker.Product's homepage


Minify Related Software