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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kd-minifier

v1.0.8

Published

modified from minifier

Readme

minifier

A simple tool for minifying CSS/JS without a big setup.

Feature highlights

  • It minifies JS and CSS
  • URLs in CSS are updated relative to the output location
  • It automatically resolves @import statements in CSS.

How to install

There are two ways to install it:

  1. npm install [-g] minifier
  2. Cloning directly from github.

Installing through npm will create a binary (minify) in the usual locations. Cloning and installing from github will not, but the index.js file can be executed either directly or via node index.js; this is the file that the binary links to anyway.

How to run from a command-line

Running it is simple:

minify [--output path/to/put/file] path/to/file

If the output parameter is not set, it will place a file next to the original, with the suffix .min.

For example, minifier script.js will output script.min.js, whereas minifier --output out.js script.js will output out.js.

A folder can also be targeted. When that is done, it will minify all css and js file in that folder.

In that case, --output does not make much sense, as all files will be minified to the same. If the name still requires a specific pattern such as a timestamp, --template is the option for you. Note that files named after a template will be left in the same folder as the original file.

There are various options available:

  • {{filename}} is the original filename.
  • {{ext}} is the extension.
  • {{sha}} is a sha-digest of the unminified file contents.
  • {{md5}} is a md5-digest of the unminified file contents.

For example, {{filename}}-{{md5}}.min.{{ext}} will make abc.js into something like abc-f90731d65c61af25b149658a120d26cf.min.js.

To avoid the minification of previously minified files, there is a --clean option, which will delete all files that match the output pattern.

This also means that any real files that match the pattern will be removed as well, so please be careful.

Running from a node-script

It is also possible to run the minifier from within another node script:

var minifier = require('minifier')
var input = '/some/path'

minifier.on('error', function(err) {
	// handle any potential error
})
minifier.minify(input, options)

As with the command-line variant, the input should be a path to either a javascript file, a css file or a folder.

The options-dictionary takes the same parameters as the command-line variant:

  • output: A path-string that tells where to put the output.
  • template: A string template for how to build the outputted filenames.
  • clean: A bool for whether other files with names similar to the template should be deleted before minifying the contents of a folder.
  • cleanOnly: A bool for whether to run with clean option and then exiting before minifying any files.

There are one important additional option: uglify. This will be passed on to uglify, so that the minification can be controlled. See the uglify documentation for more details (the uglify.minify(path, opts) function is used internally).


The method for building the output name from the template is exposed for convenience:

var minifier = require('minifier')
var file = 'abc.js'
var template = '{{filename}}.{{md5}}.{{ext}}'
var content = null; // or the content, if md5 or sha1 should be calculated
var result = minifier.generateOutputName(file, { template: template, content: content })

If the input-path includes any folders, they will also be added to the output.

If content is eschewed, the md5 and sha digests cannot be calculated.

But there is an option for turning them into either RegExp or glob compatible syntax: Simply add glob: true or regex: true to the options array:

var result = minifier.generateOutputName(file, { template: template, glob: true })

glob will return a string for passing to a glob function, whereas regex will return a RegExp instance for manual comparison.

Concatenating multiple javascript files

It is possible to concatenate multiple javascript files into a single, minified file.

Simply pass multiple in via the CLI interface, or pass an array to the API.

They will have the same order as the input-parameter.

CSS URL Rewrites

Any URLs that are found in CSS files, are automatically updated relative to the output destination. An example is shown below:

- styles.css
- dist/
  - styles.min.css
- lib/
  - backgrond.jpg


styles.css

.background {
  background-image: url("lib/background.jpg");
}

styles.min.css

.background {
  background-image: url("../lib/background.jpg");
}

Running the tests

After installing from github, simply run npm test.

There is a script called prepareManualTests.js, which will run the script against the css-files inside test/manual/css/ and provides a real-world example of the CSS minification tools.

The manual tests can be seen by opening test/manual/index.html in a browser after executing prepareManualTests.js.

Credits

In no particular order:

  • duckduckgo for the image used by the manual tests.
  • sqwish for minifying CSS files.
  • uglify-js for minifying JS files.
  • commander for command-line interaction.
  • mocha and chai for testing home-brewed logic.
  • glob for trawling through the file-system when targetting a folder.
  • hogan.js for parsing the template string.