minify
Minifier of js, css, html and img
Last updated 10 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install minify 
SYNC missed versions from official npm registry.

Minify License Build Status NPM version Coverage Status

Minify - a minifier of js, css, html and img files.

To get things done Minify uses this amazing tools:

Install

For Node users:

npm i minify -g

For Deno users:

import {minify} from 'npm:minify';

How to use?

CLI

Usage: minify [options]
Options:
  -h, --help                  display this help and exit
  -v, --version               display version and exit
  --js                        minify javascript
  --css                       minify css
  --html                      minify html
  --auto                      auto detect format

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 <enter>.

$ 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
var a='world';for(let i=0;i<a.length;i++)console.log(a[i]);

You can capture the output with the following:

$ minify hello.js > hello.min.js

You can pass input using cat:

cat << EOT | bin/minify.js --js
> const hello = 'world';
>
> for (let i = 0; i < hello.length; i++) {
>     console.log(hello[i]);
> }
> EOT
var a='world';for(let i=0;i<a.length;i++)console.log(a[i]);

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:

{
    "js": {
        "mangle": true,
        "mangleClassNames": true,
        "removeUnusedVariables": true,
        "removeConsole": false,
        "removeUselessSpread": true
    },
    "img": {
        "maxSize": 4096
    },
    "html": {
        "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
    },
    "css": {
        "compatibility": "*"
    }
}

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

js

In section related to js you can choose type of minifier:

When you want to pass options to terser, use section with the same name, .minify.json will look this way:

{
    "js": {
        "type": "terser",
        "terser": {
            "mangle": false
        }
    }
}

License

MIT

Current Tags

  • 11.4.1                                ...           latest (2 months ago)

162 Versions

  • 11.4.1                                ...           2 months ago
  • 11.4.0                                ...           4 months ago
  • 11.3.0                                ...           4 months ago
  • 11.2.1                                ...           5 months ago
  • 11.2.0                                ...           6 months ago
  • 11.1.1                                ...           8 months ago
  • 11.1.0                                ...           8 months ago
  • 11.0.1                                ...           a year ago
  • 11.0.0                                ...           a year ago
  • 10.5.2                                ...           a year ago
  • 10.5.1                                ...           a year ago
  • 10.5.0                                ...           a year ago
  • 10.4.0                                ...           a year ago
  • 10.3.0                                ...           a year ago
  • 10.2.0                                ...           a year ago
  • 10.1.0                                ...           a year ago
  • 10.0.0                                ...           2 years ago
  • 9.2.0                                ...           2 years ago
  • 9.1.0                                ...           2 years ago
  • 9.0.0                                ...           2 years ago
  • 8.0.4                                ...           3 years ago
  • 8.0.3                                ...           3 years ago
  • 8.0.2                                ...           3 years ago
  • 8.0.1                                ...           3 years ago
  • 8.0.0                                ...           3 years ago
  • 7.2.2                                ...           3 years ago
  • 7.2.1                                ...           3 years ago
  • 7.2.0                                ...           3 years ago
  • 7.1.0                                ...           3 years ago
  • 7.0.2                                ...           4 years ago
  • 7.0.1                                ...           4 years ago
  • 7.0.0                                ...           4 years ago
  • 6.0.1                                ...           4 years ago
  • 6.0.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.1                                ...           5 years ago
  • 5.1.0                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 4.1.3                                ...           5 years ago
  • 4.1.2                                ...           5 years ago
  • 4.1.1                                ...           6 years ago
  • 4.1.0                                ...           6 years ago
  • 4.0.3                                ...           6 years ago
  • 4.0.2                                ...           6 years ago
  • 4.0.1                                ...           6 years ago
  • 4.0.0                                ...           6 years ago
  • 3.0.5                                ...           7 years ago
  • 3.0.4                                ...           7 years ago
  • 3.0.3                                ...           7 years ago
  • 3.0.2                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 2.1.8                                ...           7 years ago
  • 2.1.7                                ...           7 years ago
  • 2.1.6                                ...           7 years ago
  • 2.1.5                                ...           7 years ago
  • 2.1.4                                ...           7 years ago
  • 2.1.3                                ...           7 years ago
  • 2.1.2                                ...           7 years ago
  • 2.1.1                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.14                                ...           8 years ago
  • 2.0.13                                ...           8 years ago
  • 2.0.12                                ...           8 years ago
  • 2.0.11                                ...           8 years ago
  • 2.0.10                                ...           8 years ago
  • 2.0.9                                ...           9 years ago
  • 2.0.8                                ...           9 years ago
  • 2.0.7                                ...           9 years ago
  • 2.0.6                                ...           9 years ago
  • 2.0.5                                ...           9 years ago
  • 2.0.4                                ...           9 years ago
  • 2.0.3                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.4.23                                ...           9 years ago
  • 1.4.22                                ...           9 years ago
  • 1.4.21                                ...           9 years ago
  • 1.4.20                                ...           9 years ago
  • 1.4.19                                ...           9 years ago
  • 1.4.18                                ...           9 years ago
  • 1.4.17                                ...           9 years ago
  • 1.4.16                                ...           9 years ago
  • 1.4.15                                ...           9 years ago
  • 1.4.14                                ...           9 years ago
  • 1.4.13                                ...           9 years ago
  • 1.4.12                                ...           10 years ago
  • 1.4.11                                ...           10 years ago
  • 1.4.10                                ...           10 years ago
  • 1.4.9                                ...           10 years ago
  • 1.4.8                                ...           10 years ago
  • 1.4.7                                ...           10 years ago
  • 1.4.6                                ...           10 years ago
  • 1.4.5                                ...           10 years ago
  • 1.4.4                                ...           10 years ago
  • 1.4.3                                ...           10 years ago
  • 1.4.2                                ...           10 years ago
  • 1.4.1                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.6                                ...           10 years ago
  • 1.3.5                                ...           10 years ago
  • 1.3.4                                ...           10 years ago
  • 1.3.3                                ...           10 years ago
  • 1.3.2                                ...           10 years ago
  • 1.3.1                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.13                                ...           10 years ago
  • 1.0.12                                ...           10 years ago
  • 1.0.11                                ...           10 years ago
  • 1.0.10                                ...           10 years ago
  • 1.0.9                                ...           10 years ago
  • 1.0.8                                ...           10 years ago
  • 1.0.7                                ...           10 years ago
  • 1.0.6                                ...           10 years ago
  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.9.0                                ...           10 years ago
  • 0.8.4                                ...           10 years ago
  • 0.8.3                                ...           10 years ago
  • 0.8.2                                ...           10 years ago
  • 0.8.1                                ...           10 years ago
  • 0.8.0                                ...           10 years ago
  • 0.7.1                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.4                                ...           10 years ago
  • 0.6.3                                ...           10 years ago
  • 0.6.2                                ...           10 years ago
  • 0.6.1                                ...           10 years ago
  • 0.6.0                                ...           10 years ago
  • 0.5.1                                ...           11 years ago
  • 0.5.0                                ...           11 years ago
  • 0.4.1                                ...           11 years ago
  • 0.4.0                                ...           11 years ago
  • 0.3.4                                ...           11 years ago
  • 0.3.3                                ...           11 years ago
  • 0.3.2                                ...           11 years ago
  • 0.3.1                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.6                                ...           11 years ago
  • 0.2.5                                ...           11 years ago
  • 0.2.4                                ...           11 years ago
  • 0.2.3                                ...           11 years ago
  • 0.2.2                                ...           11 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.9                                ...           12 years ago
  • 0.1.8                                ...           12 years ago
  • 0.1.7                                ...           12 years ago
  • 0.1.6                                ...           12 years ago
  • 0.1.5                                ...           12 years ago
  • 0.1.4                                ...           12 years ago
  • 0.1.3                                ...           12 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 2
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE