rollup-plugin-minify-html-literals-v3

raw JSON →
1.3.4 verified Mon Apr 27 auth: no javascript

Rollup plugin to minify HTML template literal strings, forked from the official rollup-plugin-minify-html-literals to support Rollup v3 and later (including Rollup v4). Version 1.3.4 ships TypeScript types and works as a drop-in replacement. The plugin minifies tagged template literals (e.g., lit-html, html`...`, css`...`), with fine-grained include/exclude filters. It wraps the minify-html-literals library and offers full options passthrough. Compared to the original, this fork updates the Rollup peer dependency range; no code changes beyond that. Official repo is still on Rollup v2, so this fork remains active until upstream is updated.

error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Using require() on this ESM-only package.
fix
Change to import syntax: import minifyLiterals from 'rollup-plugin-minify-html-literals-v3'
error TypeError: minifyLiterals is not a function
cause Named import instead of default import: import { minifyLiterals } from ...
fix
Remove curly braces: import minifyLiterals from 'rollup-plugin-minify-html-literals-v3'
error The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
cause Rollup config file using CommonJS require inside an ESM context.
fix
Rename file to rollup.config.js (not .cjs) and use import syntax, or use dynamic import.
error Could not resolve 'minify-html-literals'
cause Missing dependency, or incorrect import path.
fix
Install minify-html-literals: npm install minify-html-literals
breaking This package is a fork; do not confuse with the original rollup-plugin-minify-html-literals
fix Ensure you have the correct package name: rollup-plugin-minify-html-literals-v3
gotcha The plugin is ESM-only. Using require() will throw an error.
fix Use import syntax or dynamic import with .default as shown in imports.
deprecated Rollup v3 support is being phased out; this package works with Rollup v4 but may require updating peer dependencies.
fix If using Rollup v4, ensure rollup-plugin-minify-html-literals-v3 is at version 1.3.0 or higher.
gotcha The options.minifyOptions are passed directly to html-minifier; some defaults may over-minify (e.g., removing quotes, unsafe for attributes).
fix Review default minify options and override if needed – especially keepClosingSlash and collapseBooleanAttributes.
gotcha Including or excluding files: default include is all files; if you only want to minify certain extensions, set include explicitly.
fix Set include: '**/*.js' or a more specific minimatch pattern to avoid unexpectedly processing non-JS files.
npm install rollup-plugin-minify-html-literals-v3
yarn add rollup-plugin-minify-html-literals-v3
pnpm add rollup-plugin-minify-html-literals-v3

Basic rollup.config.js using default import of the plugin with include filter and custom minify options.

// rollup.config.js
import minifyLiterals from 'rollup-plugin-minify-html-literals-v3';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [
    minifyLiterals({
      include: 'src/**/*.js',
      options: {
        minifyOptions: {
          caseSensitive: true,
          collapseWhitespace: true
        }
      }
    })
  ]
};