Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/srod/node-minify

Light Node.js module that compress javascript, css and html files
https://github.com/srod/node-minify

babel-minify clean-css cli crass csso gcc google-closure-compiler html html-minifier html5 javascript json minify nodejs sqwish terser uglify-es uglify-js yui yui-compressor

Last synced: 10 days ago
JSON representation

Light Node.js module that compress javascript, css and html files

Awesome Lists containing this project

README

        

node-minify

A very light minifier Node.js module.






Build Status

# Features

It allow you to compress JavaScript, CSS and HTML files.

**JavaScript:**

- [babel-minify](https://node-minify.2clics.net/compressors/babel-minify)
- [Google Closure Compiler](https://node-minify.2clics.net/compressors/gcc)
- [terser](https://node-minify.2clics.net/compressors/terser)
- [uglify-js](https://node-minify.2clics.net/compressors/uglify-js)
- [uglify-es](https://node-minify.2clics.net/compressors/uglify-es)
- [YUI Compressor](https://node-minify.2clics.net/compressors/yui)

**CSS:**

- [clean-css](https://node-minify.2clics.net/compressors/clean-css)
- [crass](https://node-minify.2clics.net/compressors/crass)
- [cssnano](https://node-minify.2clics.net/compressors/cssnano)
- [CSSO](https://node-minify.2clics.net/compressors/csso)
- [sqwish](https://node-minify.2clics.net/compressors/sqwish)
- [YUI Compressor](https://node-minify.2clics.net/compressors/yui)

**HTML:**

- [html-minifier](https://node-minify.2clics.net/compressors/html-minifier)

**Command Line Interface:**

- [CLI](https://node-minify.2clics.net/cli)

## Installation

```bash
npm install @node-minify/core
# Or Yarn
yarn add @node-minify/core
# Or pnpm
pnpm add @node-minify/core
```

And install the compressor you want

```bash
npm install @node-minify/uglify-js
# Or Yarn
yarn add @node-minify/uglify-js
# Or pnpm
pnpm add @node-minify/uglify-js
```

## Quick Start

```js
import minify from '@node-minify/core';
import gcc from '@node-minify/google-closure-compiler';
import uglifyjs from '@node-minify/uglify-js';

// Using Google Closure Compiler
minify({
compressor: gcc,
input: 'foo.js',
output: 'bar.js',
callback: function (err, min) {}
});

// Using UglifyJS
minify({
compressor: uglifyjs,
input: './**/*.js',
output: 'bar.js',
callback: function (err, min) {}
});

// Using Promise
var promise = minify({
compressor: uglifyjs,
input: './**/*.js',
output: 'bar.js'
});

promise.then(function (min) {});

// Async/Await
async function doMinify() {
const min = await minify({ compressor: uglifyjs, input: 'foo.js', output: 'bar.js' });
}
```

### In memory

```js
import htmlMinifier from '@node-minify/html-minifier';

const html = `




`;

minify({
compressor: htmlMinifier,
content: html
}).then(function (min) {
console.log('html min');
console.log(min);
});
```

[More examples](https://github.com/srod/node-minify/blob/master/examples/server.mjs)

## Documentation

Visit https://node-minify.2clics.net for full documentation.

## License

[MIT](LICENSE)