# minify /

Filename Size Date modified Message
minify
77 B
94 B
83 B
1.1 KB
47 B
6.0 KB
72 B
1.8 KB

# Minify

Minify 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 files

See the Usage section for more information about these commands.

## Installation

The 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=['minify'],
...
)


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.

## Usage

Minify provides two commands for minifying CSS and JS resources:

• minify_js which minifies Javascript files
• minify_css which minifies CSS files

### Minifying Javascript files

To show the options of the minify_js command, just type:

$python setup.py minify_js --help  You 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 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 '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 <charset> --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 optimizations 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  The 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.js


But, 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):

[minify_js]
sources = static/one.js static/two.js
output = static/combined.js
nomunge = yes


Then, 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:

[minify_js]
sources = static/one.js static/two.js
output = static/%s-min.js


Running python setup.py minify_js will then produce two minified files: static/one-min.js and static/two-min.js.

### Minifying CSS files

You can also see the options of the minify_css command, by typing:



## Support

This project is hosted on bitbucket.org. Please report issues via the bug tracker.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.