Registry / web-framework / rollup-plugin-html-literals

rollup-plugin-html-literals

JSON →
library2.0.1jsnpmunverified

A Rollup plugin (v2.0.1) that minifies HTML in tagged template literals, specifically for lit-html and other HTML-in-JS libraries. Currently stable with active maintenance; released as a compatibility fix for newer Rollup versions (^2.x.x, ^3.x.x, ^4.x.x). Unlike rollup-plugin-minify-html-literals, this plugin supports Rollup v3+ and is written in TypeScript, providing type definitions. It relies on minify-literals under the hood and must run before transpilation. Ideal for reducing bundle size in LitElement or similar projects.

npm install rollup-plugin-html-literals
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-HTML
R
rollup-plugin-html-literals
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default import (plugin function)
import template from 'rollup-plugin-html-literals'
import { template } from 'rollup-plugin-html-literals'
The plugin is exported as a default function, not a named export.
CommonJS require
const template = require('rollup-plugin-html-literals')
const { template } = require('rollup-plugin-html-literals')
For CJS projects, use default require. Named destructuring fails.
TypeScript import
import template from 'rollup-plugin-html-literals'
import * as template from 'rollup-plugin-html-literals'
Plugin ships TypeScript types; default import works with esModuleInterop.

Basic Rollup config using the plugin to minify HTML template literals in all JS files, excluding node_modules.

import template from 'rollup-plugin-html-literals'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [ template({ include: ['**/*.js'], exclude: ['node_modules/**'], failOnError: false, options: { minifyOptions: { collapseWhitespace: true, conservativeCollapse: true } } }) ] };
Debug
Known issues
gotchaPlugin must run before transpilation (e.g., before Babel or TypeScript) to avoid mangled code.
fix
Place template() before transpile plugins in the plugins array.
affects: >=0.0.0
gotchaOnly minifies template literals tagged with html; other tags like css or custom tags are not processed by default.
fix
Use minifyHTMLLiterals option to customize the minification function or configure minify-literals options accordingly.
affects: >=0.0.0
deprecatedThe minifyHTMLLiterals option is deprecated in favor of options.customMinifiers or direct minify-literals configuration.
fix
Refer to minify-literals documentation for custom minification.
affects: >=2.0.0
gotchaWhen using include/exclude patterns, they are relative to the project root and must match full paths after Rollup resolves them.
fix
Use patterns like 'src/**/*.js' instead of just '*.js'.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Could not resolve 'minify-literals'
Missing dependency minify-literals (not automatically installed as peer dependency).
fix
Run npm install minify-literals --save-dev
TypeError: template is not a function
Incorrect import: using named import instead of default import.
fix
Use import template from 'rollup-plugin-html-literals'
Error: The plugin must be placed before transpilation plugins
Order of plugins in Rollup config: template() after Babel/TypeScript.
fix
Move template() before transpile plugins in plugins array.
Unexpected token: punc (.) - Template literals not minified
Rollup version is <2 and not supported by this plugin.
fix
Upgrade Rollup to ^2.0.0 or later, or use rollup-plugin-minify-html-literals for older versions.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
minify-literalsrequiredcore minification engine for HTML template literals
rolluprequiredpeer dependency – plugin requires Rollup to function
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-html-literals — npm install rollup-plugin-html-literals · libregistry