Note: please check the tools page on the wiki for the latest information on Cappuccino’s tools.
In the third installment of the build tools series we tackle one of the most advanced build tools:
The primary goal of press is to strip unused code from your application and frameworks and perform other optimizations. It needs to know about the entire application, including your application code and the Cappuccino frameworks, in order to determine the dependencies and remove unused files. It is called with two parameters, the path to your application, and the output directory:
press root_directory output_directory
This will run press on your application located at
root_directory, and output a similar but smaller version (with unused files stripped) at
Additionally, there are several useful options:
‐‐main path: The relative path (from root_directory) to the main file (default:
‐‐frameworks path: The relative path (from root_directory) to the frameworks directory (default:
pngcrushon all PNGs (
pngcrushmust be installed!)
‐‐flatten: Flatten all code into a single Application.js file and attempt to add script tag to
index.html(useful for Adobe AIR and CDN deployment)
- ‐‐nostrip: Don’t strip any files. Mostly useful for debugging.
The most interesting of these options is
If you’re interested in how press works, read on. It starts by loading your application while noting which global variables are defined in each file. It then “walks” along the dependency “graph”, including every imported file, with one important exception: framework imports like
import <AppKit/AppKit.j> and
import <Foundation/Foundation.j> are ignored since these types of imports would result in the entire framework (including unused files) being imported. Instead, press looks at the global dependencies, and only keeps the files that are referenced by any other file that has been imported.
press is a already a great tool, but there is much room for improvement. In the future we would like to add finer-granularity code stripping, such as method-level rather than file-level. Additionally, we’re working on an automatic image spriting and optimization feature which determines exactly which images are required for your application and includes them in a single image, vastly reducing the number of HTTP requests to load your application.