Registry / testing / html-template-minifier-webpack

html-template-minifier-webpack

JSON →
library1.1.0jsnpmunverified

A Webpack loader that minifies HTML templates embedded in JavaScript files, targeting lit-html and similar template literal-based libraries (version 1.1.0). Unlike html-minifier, it handles `${}` interpolations without requiring well-formed HTML, applying rules like comment removal and space compression. Lightweight but simplistic, with no active releases since 2020. Differentiators include template literal awareness and minimal configuration, at the cost of robustness against complex nesting.

npm install html-template-minifier-webpack
INSTALL
IMPORT
SIG · HTML-TEMPLATE-MINI
H
html-template-minifier-webpack
testingjavascriptv1.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.

html-template-minifier-webpack
const HtmlTemplateMinifier = require('html-template-minifier-webpack');
import HtmlTemplateMinifier from 'html-template-minifier-webpack';
Package does not ship ESM; use CommonJS require.

Shows a minimal webpack configuration to minify HTML templates in JS files using the loader.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, use: 'html-template-minifier-webpack', }, ], }, }; // In your JS file containing HTML templates: import { html } from 'lit-html'; const template = html`<div class="container"> <!-- comment --> ${value} </div>`;
Debug
Known issues
gotchaNested `<pre>` or `${}` blocks can confuse the simplistic pattern matching. For example, nested template literals inside `${}` may not be minified correctly.
fix
Avoid deeply nested template literals inside `${}` or use a more robust minifier.
affects: <=1.1.0
gotchaThe minifier only applies basic rules: comment removal and space collapsing. It does not perform comprehensive HTML minification like removing optional tags or shortening attributes.
fix
If advanced minification is needed, consider using html-minifier-terser or another tool after template processing.
affects: <=1.1.0
gotchaThe loader assumes your templates use template literals with `${}` for JavaScript expressions. Templates using other syntax (e.g., Mustache) may not be minified.
fix
Only use with JavaScript template literal-based HTML templates.
affects: <=1.1.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'html-template-minifier-webpack'
Package not installed or missing from node_modules.
fix
Run 'npm install html-template-minifier-webpack --save-dev'
ERROR in ./src/app.js Module build failed (from ./node_modules/html-template-minifier-webpack/index.js): Template literal not found
The loader expects template literals with backticks (`) in the file. If no such template is found, it may produce an error or skip minification.
fix
Ensure the file contains template literals with HTML content, or exclude non-template files from the loader rule.
TypeError: this.getOptions is not a function
Loader is not compatible with Webpack 5's loader API (getOptions). It expects Webpack 4's loader context.
fix
Upgrade to Webpack 4 or use a different minifier that supports Webpack 5.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
webpackrequiredWebpack loader, requires webpack to function
Agent activity
4 hits · last 30 days
node
4
Resources
html-template-minifier-webpack — npm install html-template-minifier-webpack · libregistry