npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minify

v11.4.1

Published

Minifier of js, css, html and img

Downloads

182,332

Readme

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 .

$ 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