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

@tdewolff/minify

v2.24.8

Published

Go minifiers for web formats

Downloads

325

Readme

JavaScript bindings around the Go minifiers in tdewolff/minify. The package ships a small native library built from Go and exposes a single async minify function. Requires Node.js 20.19+.

Quickstart

npm install @tdewolff/minify
import { readFile, writeFile } from 'node:fs/promises'
import { minify } from '@tdewolff/minify'

// Inline string
const html = await minify({
  data: `<html><span class="text" style="color:#ff0000;">A  phrase</span></html>`,
  type: 'text/html',
  htmlKeepDocumentTags: true
})
console.log(html) // <html><span class=text style=color:red>A phrase</span></html>

// File input/output
const source = await readFile('example.html', 'utf8')
const minified = await minify({ data: source, type: 'text/html', htmlKeepDocumentTags: true })
await writeFile('example.min.html', minified, 'utf8')

// Overload with explicit type/data parameters
const minifiedHtml = await minify('text/html', source, { htmlKeepDocumentTags: true })

API

import { minify, type MinifyConfig, type MinifyMediaType, type MinifyOptions } from '@tdewolff/minify'

declare function minify(opts: MinifyOptions): Promise<string>
declare function minify(type: MinifyMediaType, data: string, config?: MinifyConfig | null): Promise<string>

MinifyOptions fields (all optional except data and type):

  • data: string content to minify.
  • type: mediatype used to pick the minifier (see below).
  • cssPrecision, cssVersion
  • htmlKeepComments, htmlKeepConditionalComments, htmlKeepDefaultAttrvals, htmlKeepDocumentTags, htmlKeepEndTags, htmlKeepQuotes, htmlKeepSpecialComments, htmlKeepWhitespace
  • jsKeepVarNames, jsPrecision, jsVersion
  • jsonKeepNumbers, jsonPrecision
  • svgKeepComments, svgPrecision
  • xmlKeepWhitespace

Errors are thrown for missing data, invalid types, or native parse errors.

Mediatypes

These types are accepted by the Go minifiers (regex-style JSON/XML/JS matches are supported):

  • text/css
  • text/html
  • image/svg+xml
  • JavaScript media types matching (application|text)/(x-)?(java|ecma|j|live)script and module
  • Any type ending in /json or +json, and importmap/speculationrules
  • Any type ending in /xml or +xml

Native build

npm install runs npm run build:go, which builds build/<goos>-<goarch>/minify.{so|dll|dylib} using Go 1.24+ and a C compiler. The library is resolved automatically based on process.platform/process.arch.

Useful knobs:

  • NODE_MINIFY_LIB_PATH: point to an existing compiled library to skip detection.
  • NODE_MINIFY_SKIP_BUILD=1: skip building (ensure the library already exists).
  • NODE_MINIFY_FORCE_BUILD=1: rebuild even if a library is present.
  • NODE_MINIFY_DEBUG_BUILD=1: keep symbols/paths (no strip flags).
  • GOOS/GOARCH: cross-build, e.g. GOOS=windows GOARCH=amd64 npm run build:go.