
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Minify - a minifier of js
, css
, html
and img
files.
To get things done Minify uses this amazing tools:
For Node users:
npm i minify -g
For Deno users:
import {minify} from 'npm:minify';
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);
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:
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
}
}
}
MIT
FAQs
Minifier of js, css, html and img
The npm package minify receives a total of 28,741 weekly downloads. As such, minify popularity was classified as popular.
We found that minify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.