Registry / babel-plugin-template-html-minifier
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.
Plugin config
✓ // In .babelrc or babel.config.js:
{
"plugins": [
["template-html-minifier", { "modules": { "lit-html": ["html"] } }]
]
}
✗ // Wrong plugin name
{
"plugins": ["babel-plugin-template-html-minifier"]
}
Plugin name in Babel config is 'template-html-minifier' (without '@babel/' prefix). The second element in the array is the options object.
Programmatic usage
✓ import plugin from 'babel-plugin-template-html-minifier';
// passes options as second argument to Babel transform
✗ const plugin = require('babel-plugin-template-html-minifier');
// plugin is a function, not a default export
This package is a Babel plugin, usually consumed via Babel config. Programmatic usage: import and pass to Babel's transform function.
TypeScript
✓ // No TypeScript types are bundled; use @types/babel__core for plugin typings
✗ import plugin from 'babel-plugin-template-html-minifier';
// TypeScript may complain about missing module
If using TypeScript, install @types/babel__core for plugin support. No ambient types provided.
Shows how to configure the plugin to minify lit-html templates in Babel.
// Create a JavaScript file with a tagged template:
import { html } from 'lit-html';
const title = 'Hello World';
const template = html`
<div class="container">
<h1>${title}</h1>
<p>Some text</p>
</div>
`;
// .babelrc:
{
"plugins": [
["template-html-minifier", {
"modules": {
"lit-html": ["html"]
},
"htmlMinifier": {
"collapseWhitespace": true,
"removeComments": true
}
}]
]
}
// After Babel transformation, the template will be minified:
// const template = html`
// <div class="container"><h1>${title}</h1><p>Some text</p></div>
// `;
Errors
Common errors & fixes
Error: `removeComments` is not safe when template contains expression inside comment
html-minifier removes comments including dynamic expressions, which changes behavior
fixSet htmlMinifier.removeComments to false or ensure no dynamic expressions inside comments
Error: `collapseBooleanAttributes` is not safe when template contains expression in boolean attribute
Minifier collapses boolean attributes and removes the placeholder for the expression
fixSet htmlMinifier.collapseBooleanAttributes to false
The plugin name must be 'template-html-minifier' not 'babel-plugin-template-html-minifier'
Babel expects the short name without the babel-plugin- prefix when using array format
fixUse ['template-html-minifier', options] in plugins
Audit
Dependencies
html-minifier-terserrequiredCore HTML minification logic