srod / node-minify

Light Node.js module that compress javascript, css and html files
https://node-minify.2clics.net
MIT License
509 stars 54 forks source link
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

node-minify

A very light minifier Node.js module.


Build Status

Features

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

JavaScript:

CSS:

HTML:

Command Line Interface:

Installation

npm install @node-minify/core
# Or Yarn
yarn add @node-minify/core
# Or pnpm
pnpm add @node-minify/core
# Or Bun
bun add @node-minify/core

And install the compressor you want

npm install @node-minify/uglify-js
# Or Yarn
yarn add @node-minify/uglify-js
# Or pnpm
pnpm add @node-minify/uglify-js
# Or Bun
bun add @node-minify/uglify-js

Quick Start

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

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

const html = `
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
</html>`;

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

More examples

Documentation

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

License

MIT