Registry / devops / minify-literals

minify-literals

JSON →
library2.0.1jsnpmunverified

Minify CSS and HTML literals inside JavaScript/TypeScript template literal strings. Version 2.0.1 is current stable. Uses html-minifier-next for HTML and lightningcss for CSS. Differentiators: supports TypeScript sources, source maps, and custom tag names. ESM-only, requires Node >=22. Active development.

npm install minify-literals
INSTALL
IMPORT
SIG · MINIFY-LITERALS
M
minify-literals
devopsjavascriptv2.0.1
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.

minifyHTMLLiterals
import { minifyHTMLLiterals } from 'minify-literals'
const minifyHTMLLiterals = require('minify-literals')
ESM-only; use import syntax. TypeScript types are included.
default
import minifyLiterals from 'minify-literals'
import { minifyLiterals } from 'minify-literals'
Default export available for convenience, but named export is preferred.
type Options
import type { Options } from 'minify-literals'
import { Options } from 'minify-literals'
Options is a type; use type-only import to avoid runtime impact.

Shows basic usage: minify HTML and CSS template literals in a JS/TS source string, outputting minified code and a source map.

import { minifyHTMLLiterals } from 'minify-literals'; const source = ` const el = html\`<div > <h1> Hello World </h1 > </div>\`; const css = css\` .foo { color: red; } \`; `; const { code, map } = await minifyHTMLLiterals(source); console.log(code); // const el = html`<div><h1>Hello World</h1></div>`; // const css = css`.foo{color:red}`;
Debug
Known issues
breakingv2 is a complete rewrite; API has changed from v1. Check migration guide.
fix
Update imports and options. Use named export `minifyHTMLLiterals` instead of `minifyHTMLLiterals` (note: same name). Refer to docs.
affects: >=2.0.0
breakingMinimum Node.js version is now 22; older versions not supported.
fix
Upgrade Node.js to v22 or later.
affects: >=2.0.0
gotchaESM-only; CommonJS require() will throw.
fix
Use `import` syntax. If you must use CJS, use dynamic import: `const { minifyHTMLLiterals } = await import('minify-literals')`.
affects: >=2.0.0
deprecatedThe configuration option `htmlOptions`/`cssOptions` are replaced with `html`/`css` objects.
fix
Use `html: { ... }` and `css: { ... }` directly in options.
affects: <2.0.0
gotchaSource maps are generated by default; to disable, set `sourceMap: false`.
fix
Explicitly set `sourceMap: false` in options if not needed.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Attempting CommonJS require() on an ESM-only package.
fix
Use `import` syntax or dynamic `import()` instead.
TypeError: minifyHTMLLiterals is not a function
Incorrect import (e.g., default import when using named export or vice versa).
fix
Check import: use `import { minifyHTMLLiterals } from 'minify-literals'`.
Cannot find module 'html-minifier-next'
Missing peer dependency installed.
fix
Run `npm install html-minifier-next lightningcss`.
node:internal/modules/run_main:122 ... The NODE_COMPILE_CACHE...
Node.js version <22.
fix
Upgrade Node.js to v22 or later.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
html-minifier-nextrequiredHTML minification engine
lightningcssrequiredCSS minification engine
Agent activity
2 hits · last 30 days
node
2
Resources
minify-literals — npm install minify-literals · libregistry