Registry / devops / html-minify-stream

html-minify-stream

JSON →
library2.0.0jsnpmunverified

Node.js transform stream for minifying HTML using html-minifier. Version 2.0.0 allows streaming HTML documents and passes options directly to html-minifier. Ideal for build pipelines where HTML content is streamed from files or other streams. Does not buffer entire input, enabling low-memory processing of large HTML files. Note that html-minifier is not a pure stream; the stream collects input and processes it on end, but at least it handles backpressure. Primary differentiator from other minification libraries is its streaming interface for Node.js.

npm install html-minify-stream
INSTALL
IMPORT
SIG · HTML-MINIFY-STREAM
H
html-minify-stream
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const htmlMinifyStream = require('html-minify-stream')
import htmlMinifyStream from 'html-minify-stream'
Package uses CommonJS; no named or default ES export. Use require() or use createRequire.
htmlMinifyStream
const htmlMinifyStream = require('html-minify-stream')
const { htmlMinifyStream } = require('html-minify-stream')
The module exports a function directly, not an object with a method.
type import (TypeScript)
import htmlMinifyStream = require('html-minify-stream')
import htmlMinifyStream from 'html-minify-stream'
TypeScript with esModuleInterop: use import = require() for CJS modules.

Creates a read stream from index.html, pipes through minification, writes to dist/index.html

const htmlMinifyStream = require('html-minify-stream') const fs = require('fs') fs.createReadStream('index.html') .pipe(htmlMinifyStream({ collapseWhitespace: true, removeOptionalTags: true })) .pipe(fs.createWriteStream('dist/index.html'))
Debug
Known issues
gotchaThe stream only emits the complete minified HTML on 'end'. It does not output partial data incrementally.
fix
Expect the entire output at once; do not consume chunk by chunk.
affects: >=1.0 <3
gotchaOptions are passed directly to html-minifier; some options may conflict or cause unexpected behavior.
fix
Refer to html-minifier documentation for supported options.
affects: >=1.0 <3
deprecatedThe package uses html-minifier v4, which is no longer actively maintained.
fix
Consider switching to a more actively maintained alternative.
affects: >=2.0
Errors
Common errors & fixes
TypeError: htmlMinifyStream is not a function
Using ES module import syntax with this CommonJS package without proper configuration.
fix
Use require('html-minify-stream') instead of import.
Error: Cannot find module 'html-minify-stream'
Package not installed or Node.js cannot resolve it.
fix
Run npm install html-minify-stream in your project directory.
TypeError: Invalid non-string/buffer chunk
Attempting to pipe non-string/Buffer data into the stream.
fix
Ensure the upstream stream emits strings or Buffers. Use fs.createReadStream with encoding or set encoding on stream.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
html-minifierrequiredCore minification engine
readable-streamrequiredStream base (safe polyfill for older Node versions)
Agent activity
4 hits · last 30 days
node
4
Resources
html-minify-stream — npm install html-minify-stream · libregistry