Registry / devops / astro-minify-html

astro-minify-html

JSON →
library0.1.1jsnpmunverified

An Astro integration that minifies static HTML output using html-minifier-terser at build time. Current stable version is 0.1.1, released as an early-stage package with no breaking changes reported. It provides a simple integration function that wraps html-minifier-terser options, allowing removal of comments, whitespace, and other optimizations. Unlike raw usage of html-minifier-terser, this integration automatically hooks into Astro's build pipeline and applies minification to all generated HTML pages with zero configuration required.

npm install astro-minify-html
INSTALL
IMPORT
SIG · ASTRO-MINIFY-HTML
A
astro-minify-html
devopsjavascriptv0.1.1
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.

minifyHtml
import { minifyHtml } from 'astro-minify-html'
import { minifyHtml } from 'astro-minify-html/dist/index.mjs'
The package exports a named function; default import is not supported. TypeScript types are included.
minifyHtml
const { minifyHtml } = require('astro-minify-html')
const minifyHtml = require('astro-minify-html')
CommonJS require works, but must destructure the named export.
minifyHtml
import { minifyHtml } from 'astro-minify-html'
import { htmlMinifier } from 'astro-minify-html'
The function is named 'minifyHtml', not 'htmlMinifier' or 'minify'.

Configures Astro to minify HTML output, removing comments, collapsing whitespace, and minifying inline CSS/JS.

import { defineConfig } from 'astro/config'; import { minifyHtml } from 'astro-minify-html'; export default defineConfig({ integrations: [ minifyHtml({ removeComments: true, collapseWhitespace: true, minifyCSS: true, minifyJS: true, }) ] });
Debug
Known issues
breakingThe integration only works with static HTML output (SSG mode). SSR or on-demand rendered pages are not minified.
fix
Ensure your Astro project uses output: 'static' and does not use server-side rendering for pages you want minified.
affects: >=0.0.1
gotchaOptions are passed directly to html-minifier-terser; some options may break your HTML (e.g., removeAttributeQuotes, collapseBooleanAttributes).
fix
Test minification options thoroughly in a staging environment. Refer to html-minifier-terser docs for known caveats.
affects: >=0.0.1
gotchaThe integration runs only during the build step; it does not minify in development mode.
fix
This is by design. To see minified output, run 'astro build' and inspect the dist folder.
affects: >=0.0.1
deprecatedVersion 0.1.1 is the latest; no breaking changes reported but the package is young and API may change in future versions.
fix
Pin to exact version in package.json to avoid unexpected changes.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: minifyHtml is not a function
Default import used instead of named import.
fix
Use 'import { minifyHtml } from 'astro-minify-html'
ERR_REQUIRE_ESM: require() of ES Module not supported
Using 'require' with an ESM-only package might fail if the package is configured as ESM.
fix
Use dynamic import: 'const { minifyHtml } = await import('astro-minify-html')'
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
html-minifier-terserrequiredCore minification engine; all options are passed through to this package.
astrorequiredPeer dependency to integrate with Astro's build process.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
astro-minify-html — npm install astro-minify-html · libregistry