Skip to content

Latest commit

 

History

History
112 lines (82 loc) · 2.1 KB

HELP.md

File metadata and controls

112 lines (82 loc) · 2.1 KB

Minify

Minify - a minifier of js, css, html and img files, used in Cloud Commander project.

To use minify as middleware try Mollify.

Install

NPM_INFO

You can install minify via npm:

npm i minify -g

Command Line

Command line syntax:

minify <input-file1> <input-file2> <input-fileN> > output
stdout | minify -<flag>

For example:

minify client.js util.js > all.js
minify screen.css reset.css > all.css

cat client.js | minify -js
cat *.css | minify -css

API

The Minify module contains an api for interacting with other js files.

minify = require('minify');

After minification, a file will be saved in the temporary directory.

minify - function to minificate js, html and css-files.

  • file - path to file.
  • options(optional) - object contains options.
  • callback

Possible options:

  • name
  • stream

Examples:

Optimize file

var minify = require('minify');

minify('client.js', 'name', function(error, name) {
    console.log(error || name);
});
minify('client.js', 'stream', function(error, stream) {
    var streamWrite = fs.createWriteStream('client.min.js');
    
    if (error)
        console.error(error.message);
    else
        stream.pipe(streamWrite);
});

if post processing is needed:

minify('client.js', function(error, data) {

});

Optimize data

Gets data on input. Parameters:

  • Object with data and extensions (.js, .css, img)
  • Callback

Example:

minify({
    ext: '.js',
    data: 'function hello() { if (2 > 3) console.log(\'for real\')}'
}, function(error, data) {
    console.log(error, data);
});

Express middleware

To use as express middleware [mollify](https://github.com/coderaiser/node-mollify Mollify) could be used.

License

MIT