1.0.1 • Published 14 years ago
minifymyjs v1.0.1
#minifymyjs-4-node - A wrapper for the minifyMyJs.net API
##Install
npm install minifymyjsOr if that isn't easy enough
git clone git://github.com/mattlunn/minifymyjs-4-node.git
cd request
npm link##Usage
The library comes with one method; minify(), which has the following signature:
minify(files[, options][, destination], function (err, output));files: One or more files to be minified. If providing more than one file, we expect an array. Each file specified can be either a file path (absolute or relative), or a URI.options: Optional An object whose key-values map API options to values.destination: Optional Absolute or relative path to where you'd like the minified source to be written. If a file already exists at that destination, it will be overwritten. If you omit this parameter, you'll only get access to the minified source code through the callback parameter (see below).callback: Called when the API has completed. If an error occured,errwill be a String describing the error. If the request succeeded,errwill benullandoutputwill be the minified source code. * ##Available Options
A comprehensive list of the available options (with descriptions) can be found at http://minifymyjs.net.
- To set a boolean option (something that is simply either on or off), pass
trueorfalseas the value for the option. - To set a numerical value (
max_line_length,indent_startetc.), pass the number as the value for the option. To specify variable names to exclude (
exclude[]), pass an array of variable names with the keyexclude:{ except: ['foo', 'bar', 'baz'] }
##Examples
Minifies the files jquery.js and application.js with all the default API options and writes the minifed source code to all.js
var minifier = require('minifymyjs');
minifier.minify(['http://code.jquery.com/jquery-1.7.2.js', './js/application.js'], './js/all.js', function (err, output) {
if (err) {
console.log('Whoops: ' + err);
}
});Changes some of the API options
var minifier = require('minifymyjs');
minifier.minify(['http://code.jquery.com/jquery-1.7.2.js', './js/application.js'], {
mangle: false, // don't change variable names
keep_copyright: true // keep the copyright notice in the first file
}, './js/all.js', function (err, output) {
if (err) {
console.log('Whoops: ' + err);
}
});