Registry / devops / htmlmin-loader

htmlmin-loader

JSON →
library1.0.2jsnpmunverified

A webpack loader that minifies HTML files using html-minifier. Version 1.0.2 is the latest and only release. It applies html-minifier options via webpack config under 'htmlmin-loader' key. Minimal features: no caching, no source maps. Alternatives like html-loader with minimize options are more actively maintained.

npm install htmlmin-loader
INSTALL
IMPORT
SIG · HTMLMIN-LOADER
H
htmlmin-loader
devopsjavascriptv1.0.2
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 (loader)
module: { rules: [{ test: /\.html$/, loader: 'htmlmin-loader' }] }
module: { loaders: [{ test: /\.html$/, loader: 'htmlmin-loader' }] }
webpack 2+ uses rules instead of loaders
options
/* webpack.config.js */ 'htmlmin-loader': { removeComments: true }
/* placing options inside module object directly */ module: { options: {...} }
Options are set as top-level config key, not nested under module
require (CommonJS)
const htmlminLoader = require('htmlmin-loader');
import htmlminLoader from 'htmlmin-loader';
Package does not export ESM; use CommonJS require for programmatic use

Configures webpack to minify all .html files using htmlmin-loader with common html-minifier options.

// webpack.config.js module.exports = { module: { rules: [{ test: /\.html$/i, loader: 'htmlmin-loader' }] }, 'htmlmin-loader': { removeComments: true, collapseWhitespace: true } };
Debug
Known issues
gotchaOptions must be placed at root of webpack config, not under module.rules
fix
Set 'htmlmin-loader' key at config root level, e.g. { 'htmlmin-loader': { removeComments: true } }
affects: >=1.0.0
deprecatedUse of webpack 1 'loaders' array is deprecated
fix
Use webpack 2+ 'rules' array with 'loader' property
affects: >=1.0.0
breakingNo source maps support; can cause debugging issues
fix
Use 'devtool' in webpack config and consider alternative loaders if source maps needed
affects: >=1.0.0
gotchaLoader applies html-minifier defaults; may break inline scripts or templates
fix
Explicitly set html-minifier options to preserve needed content, e.g. ignoreCustomFragments
affects: >=1.0.0
breakingNo TypeScript definitions; cannot be typed
fix
Manually declare module or use // @ts-ignore
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'html-minifier'
html-minifier is a peer dependency not automatically installed
fix
Run 'npm install html-minifier --save-dev'
Module build failed: TypeError: Cannot read property 'minify' of undefined
html-minifier not installed or not loaded correctly
fix
Verify html-minifier is installed and version >= 1.0.0
WebpackOptionsValidationError: Invalid configuration object ... 'htmlmin-loader' is not allowed
webpack 5+ no longer allows arbitrary top-level config keys
fix
Use 'loaderOptions' in rule or switch to a loader that supports webpack 5
ERROR in ./src/index.html Module build failed: Unknown option 'removeComments'
Options passed incorrectly (likely inside module.rules instead of root config)
fix
Move 'htmlmin-loader' options to root of webpack config
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
html-minifierrequiredcore minification library
Agent activity
4 hits · last 30 days
node
4
Resources
htmlmin-loader — npm install htmlmin-loader · libregistry