Registry / devops / posthtml-minifier

posthtml-minifier

JSON →
library0.1.0jsnpmunverified

PostHTML plugin that wraps HTMLMinifier to minify HTML output in PostHTML processing pipelines. Current stable version is 0.1.0, released in 2016 with no recent updates. It leverages HTMLMinifier's options for removing comments, collapsing whitespace, and other HTML optimizations. Differentiator: integrates seamlessly with PostHTML transformations, allowing minification as a final step without an extra tool.

npm install posthtml-minifier
INSTALL
IMPORT
SIG · POSTHTML-MINIFIER
P
posthtml-minifier
devopsjavascriptv0.1.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
import minifier from 'posthtml-minifier';
const minifier = require('posthtml-minifier').default;
The plugin exports a single function; use default import in ESM, const minifier = require('posthtml-minifier') in CJS works too.
posthtml
import posthtml from 'posthtml';
const posthtml = require('posthtml').posthtml;
PostHTML default export is the main function; not a named export.
minifier
posthtml().use(minifier({ removeComments: true }));
posthtml([minifier({ removeComments: true })]);
Pass the plugin to .use() method, not as an array to posthtml().

Minifies HTML by removing comments and collapsing whitespace using PostHTML pipeline.

const posthtml = require('posthtml'); const minifier = require('posthtml-minifier'); posthtml() .use(minifier({ removeComments: true, collapseWhitespace: true })) .process('<html><head><title>Test</title></head><body><!-- comment --><p>Hello</p></body></html>') .then(result => { console.log(result.html); // Output: <html><head><title>Test</title></head><body><p>Hello</p></body></html> });
Debug
Known issues
deprecatedPackage has not been updated since 2016; consider using 'posthtml-minify' or manual html-minifier integration.
fix
Switch to actively maintained alternatives like 'html-minifier-terser' combined with PostHTML manual call.
affects: >=0.1.0
gotchaHTMLMinifier options must be passed as object to the plugin; default options may not minify aggressively.
fix
Explicitly set options like removeComments: true, collapseWhitespace: true, etc.
affects: >=0.1.0
gotchaPlugin does not support async HTMLMinifier versions; error if HTMLMinifier API changes.
fix
Use compatible html-minifier version (<=4.0.0) or lock dependency.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: minifier is not a function
Using named import instead of default import in ES module environment.
fix
Use: import minifier from 'posthtml-minifier' (no braces).
Error: Cannot find module 'html-minifier'
Missing peer dependency html-minifier.
fix
Run: npm install html-minifier
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'minify' of undefined
HTMLMinifier version mismatch – likely v5+ with different API.
fix
Pin html-minifier to version ^4.0.0 in package.json.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
html-minifierrequiredHTMLMinifier is the underlying minification library; this plugin wraps it
posthtmlrequiredPostHTML is required as the plugin host in your build pipeline
Agent activity
6 hits · last 30 days
node
6
Resources
posthtml-minifier — npm install posthtml-minifier · libregistry