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

node-minify-custom-fork

v1.0.0

Published

Javascript / CSS minifier based on Babili / YUI Compressor / Google Closure Compiler / UglifyJS2 / Sqwish / Clean-css / CSSO

Downloads

24

Readme

THIS IS A CUSTOM FORK OF NODE-MINIFY REPO, ALL CREDITS GO TO THEM.

I just needed to tweak couple of lines for uglify-js to compile es2015 js. Don't be angry at me :(

NPM Version NPM Downloads Linux Build Windows Build Code Climate Test Coverage

Dependency Status devDependency Status

Node-minify

A very light minifier Node.js module.

Support:

  • Babili
  • YUI Compressor
  • Google Closure Compiler
  • UglifyJS
  • Clean-css
  • CSSO
  • Sqwish

It allow you to compress JavaScript and CSS files.

CSS benchmark : http://goalsmashers.github.io/css-minification-benchmark/

I recommend to execute it at boot time for production use.

Installation

npm install node-minify

Quick Start

var compressor = require('node-minify');

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

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

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

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

More examples

Concatenate Files

In order to concatenate files, simply pass in an array with the type no-compress.

compressor.minify({
  compressor: 'no-compress',
  input: ['foo.js', 'foo2.js', 'foo3.js'],
  output: 'bar.js',
  callback: function (err, min) {}
});

Using wildcards

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

Using sync option

compressor.minify({
  compressor: 'yui-js',
  input: 'foo.js',
  output: 'bar.js',
  sync: true,
  callback: function (err, min) {}
});

Using public folder

publicFolder allow you to specify an input and output folder.

It avoids you to specify the folder for each file.

compressor.minify({
  compressor: 'gcc',
  publicFolder: './public/',
  input: ['foo.js', 'foo2.js'],
  output: 'bar.js',
  callback: function (err, min) {}
});

Max Buffer Size

In some cases you might need a bigger max buffer size (for example when minifying really large files). By default the buffer is 1000 * 1024 which should be enough. If you however need more buffer, you can simply pass in the desired buffer size as an argument to compressor.minify like so:

compressor.minify({
  compressor: 'gcc',
  input: 'foo.js',
  output: 'bar.js',
  sync: true,
  buffer: 1000 * 1024,
  callback: function (err, min) {}
});

Passing options

You can pass an object to the compressor.

Please check available options.

Options for Babili

compressor.minify({
  compressor: 'babili',
  input: 'foo.js',
  output: 'bar.js',
  options: {
    babelrc: 'public/.babelrc',
    presets: ['es2015']
  },
  callback: function (err, min) {}
});

More informations

Options for YUI Compressor

compressor.minify({
  compressor: 'yui-js',
  input: 'foo.js',
  output: 'bar.js',
  options: {
    'line-break': 80,
    charset: 'utf8'
    ... // See more information link below
  },
  callback: function (err, min) {}
});

More informations

Options for Google Closure Compiler

compressor.minify({
  compressor: 'gcc',
  input: 'foo.js',
  output: 'bar.js',
  options: {
    compilation_level: 'WHITESPACE_ONLY',
    language: 'ECMASCRIPT6'
    ... // See more information link below
  },
  callback: function (err, min) {}
});

More informations

Options for UglifyJS

compressor.minify({
  compressor: 'uglifyjs',
  input: 'foo.js',
  output: 'bar.js',
  options: {
    warnings: true, // pass true to display compressor warnings.
    mangle: false // pass false to skip mangling names.
    output: {} // pass an object if you wish to specify additional output options. The defaults are optimized for best compression.
    compress: false // pass false to skip compressing entirely. Pass an object to specify custom compressor options.
  },
  callback: function (err, min) {}
});

More informations

Options for clean-css

compressor.minify({
  compressor: 'clean-css',
  input: 'foo.css',
  output: 'bar.css',
  options: {
    advanced: false, // set to false to disable advanced optimizations - selector & property merging, reduction, etc.
    aggressiveMerging: false // set to false to disable aggressive merging of properties.
    ... // See more information link below
  },
  callback: function (err, min) {}
});

More informations

Options for CSSO

compressor.minify({
  compressor: 'csso',
  input: 'foo.css',
  output: 'bar.css',
  options: {
    restructureOff: true // turns structure minimization off
  },
  callback: function (err, min) {}
});

More informations

Options for Sqwish

compressor.minify({
  compressor: 'sqwish',
  input: 'foo.css',
  output: 'bar.css',
  options: {
    strict: true // strict optimizations
  },
  callback: function (err, min) {}
});

More informations

Babili

Babili can compress only JavaScript files.

https://github.com/babel/babili

YUI Compressor

Yahoo Compressor can compress both JavaScript and CSS files.

http://developer.yahoo.com/yui/compressor/

Google Closure Compiler

Google Closure Compiler can compress only JavaScript files.

It will throw an error if you try with CSS files.

GCC latest version requires Java 1.8 You can use the legacy version that use Java 1.6

var compressor = require('node-minify');

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

https://developers.google.com/closure/compiler/

UglifyJS

UglifyJS can compress only JavaScript files.

It will throw an error if you try with CSS files.

https://github.com/mishoo/UglifyJS2

Clean-css

Clean-css can compress only CSS files.

https://github.com/GoalSmashers/clean-css

CSSO

CSSO can compress only CSS files.

https://github.com/css/csso

Sqwish

Sqwish can compress only CSS files.

https://github.com/ded/sqwish

Warning

It assumes that you have Java installed on your environment for both GCC and YUI Compressor. To check, run:

java -version

How to install:

Mac: https://java.com/en/download/help/mac_install.xml

Windows: https://java.com/en/download/help/windows_manual_download.xml

Linux: https://www.java.com/en/download/help/linux_x64_install.xml

Windows support

Since v0.5.0, a windows support is available for the no-compress option and uglify-js (thanks to pieces029 and benpusherhq)

License

MIT