GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - coderaiser/minify: Minifier of js, css, html and img

BranchesTags
Open more actions menu

Latest commit

 

History

1,116 Commits
1,116 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
bin
bin
 
 
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.madrun.js
.madrun.js
 
 
.npmignore
.npmignore
 
 
.nycrc.json
.nycrc.json
 
 
.putout.json
.putout.json
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
ChangeLog
ChangeLog
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
_typos.toml
_typos.toml
 
 
deno.json
deno.json
 
 
eslint.config.js
eslint.config.js
 
 
help.json
help.json
 
 
package.json
package.json
 
 

Repository files navigation

Minify License Build Status NPM version Coverage Status

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

To get things done Minify uses these amazing tools:

  • ✅ @putout/minify;
  • ✅ html-minifier-next;
  • ✅ clean-css;
  • ✅ lightningcss;
  • ✅ css-base64-images;

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

Use --fail-on-error to get a non-zero exit code when minification fails (useful in build scripts and CI):

$ minify broken.js --fail-on-error > broken.min.js
$ echo $?
1

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": {
        "type": "putout",
        "putout": {
            "quote": "'",
            "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": {
        "type": "clean-css",
        "clean-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:

  • putout; (default);
  • terser;
  • esbuild;
  • swc;
  • oxc;

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

About

Minifier of js, css, html and img

coderaiser.github.io/minify

Topics

csshacktoberfesthtmljavascriptminifyuglify

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

253 stars

Watchers

5 watching

Forks

35 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.