min

minify

Minifier of js, css, html and img

Showing:

Popularity

Downloads/wk

25.5K

GitHub Stars

140

Maintenance

Last Commit

3mos ago

Contributors

16

Package

Dependencies

10

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Minify License Dependency Status Build Status NPM version Coverage Status

Minify - a minifier of js, css, html and img files. To use minify as middleware try Mollify.

Install

npm i minify -g

How to use?

CLI

The bash command below creates a code snippet saved as "hello.js".

Simply copy + paste the code starting with cat, including the EOT on the last line, and press .

$ cat << EOT > hello.js
const hello = 'world';

for (let i = 0; i < hello.length; i++) {
    console.log(hello[i]);
}
EOT

Use the command minify followed by the path to and name of the js file intended to be minified. This will minify the code and output it to the screen.

$ minify hello.js
const hello="world";for(let l=0;l<hello.length;l++)console.log(hello[l]);

You can capture the output with the following:

$ minify hello.js > hello.min.js

Minify can be used with async-await and try-to-catch:

import {minify} from 'minify';
import tryToCatch from 'try-to-catch';
const options = {
    html: {
        removeAttributeQuotes: false,
        removeOptionalTags: false,
    },
};

const [error, data] = await tryToCatch(minify, './client.js', options);

if (error)
    return console.error(error.message);

console.log(data);

Options

For cli use these options can be provided in a JSON file named .minify.json like so:

{
    "html": {
        "removeAttributeQuotes": false
    },
    "css": {
        "compatibility": "*"
    },
    "js": {
        "ecma": 5
    },
    "img": {
        "maxSize": 4096
    }
}

minify walking up parent directories to locate and read it’s configuration file .minify.json.

Full documentation for options that each file type accepts can be found on the pages of the libraries used by minify to process the files:

Minify sets a few defaults for HTML that may differ from the base html-minifier settings:

{
    "removeComments": true,
    "removeCommentsFromCDATA": true,
    "removeCDATASectionsFromCDATA": true,
    "collapseWhitespace": true,
    "collapseBooleanAttributes": true,
    "removeAttributeQuotes": true,
    "removeRedundantAttributes": true,
    "useShortDoctype": true,
    "removeEmptyAttributes": true,
    "removeEmptyElements": false,
    "removeOptionalTags": true,
    "removeScriptTypeAttributes": true,
    "removeStyleLinkTypeAttributes": true,
    "minifyJS": true,
    "minifyCSS": true
}

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial