gulp-hmin
v0.0.4
Published
Gulp plugin for minify html files
Readme
gulp-hmin
Gulp plugin for minifying HTML files using html-minifier-next.
Description
gulp-hmin is a lightweight Gulp plugin that minifies HTML files with the powerful html-minifier-next library. It supports all standard minification options: collapsing whitespace, removing comments, minifying inline CSS and JavaScript, and many more.
Installation
npm install --save-dev gulp-hminOr using yarn:
yarn add -D gulp-hminOr using pnpm:
pnpm add -D gulp-hminUsage
ES Modules (recommended)
import { src, dest } from "gulp";
import htmlmin from "gulp-hmin";
function minifyHTML() {
return src("src/**/*.html")
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
// ... other options
}),
)
.pipe(dest("dist"));
}
export default minifyHTML;CommonJS
const { src, dest } = require("gulp");
const htmlmin = require("gulp-hmin");
function minifyHTML() {
return src("src/**/*.html")
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
}),
)
.pipe(dest("dist"));
}
exports.minify = minifyHTML;Complete Gulpfile example
import { deleteAsync } from "del";
import { series, src, dest } from "gulp";
import htmlmin from "gulp-hmin";
// Clean output directory
async function clean() {
await deleteAsync(["dist/*"]);
}
// Copy static assets (CSS, JS, images)
function copy() {
return src(["src/{css,js,images}/**/*"], { base: "src" }).pipe(dest("dist"));
}
// Minify HTML
function minify() {
return src("src/*.html")
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
}),
)
.pipe(dest("dist"));
}
// Export tasks
export { clean, copy, minify };
export const build = series(clean, copy, minify);API
htmlmin(options)
options(Object) – configuration passed directly to html-minifier-next. All options are optional.
Common options:
| Option | Type | Default | Description |
| --------------------------- | ------- | ------- | ----------------------------------- |
| collapseWhitespace | boolean | false | Collapse whitespace between tags |
| removeComments | boolean | false | Remove HTML comments |
| minifyJS | boolean | false | Minify inline JavaScript |
| minifyCSS | boolean | false | Minify inline CSS |
| removeEmptyAttributes | boolean | false | Remove attributes with empty values |
| removeRedundantAttributes | boolean | false | Remove redundant attributes |
| useShortDoctype | boolean | false | Use short doctype |
Refer to the html-minifier-next documentation for the full list of available options.
Development
The project uses TypeScript, Vitest for testing, and oxlint/oxfmt for linting and formatting.
Scripts
npm test– run tests with Vitestnpm run lint– lint source code with oxlintnpm run fix– auto‑fix lint issuesnpm run check– check formatting with oxfmtnpm run fmt– format code with oxfmtnpm run typecheck– run TypeScript type checkingnpm run validate– run lint and typecheck togethernpm run build– compile TypeScript to CommonJS and ES modules
License
MIT License. © 2025–2026 llcawc. Made with ❤ to beautiful architecture.
