{"id":22057,"library":"rollup-plugin-html-literals","title":"rollup-plugin-html-literals","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/jleeson/rollup-plugin-html-literals","tags":["javascript","rollup","rollup-plugin","minify","html","template-literals","tagged","lit-html","typescript"],"install":[{"cmd":"npm install rollup-plugin-html-literals","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-html-literals","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-html-literals","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"core minification engine for HTML template literals","package":"minify-literals","optional":false},{"reason":"peer dependency – plugin requires Rollup to function","package":"rollup","optional":false}],"imports":[{"note":"The plugin is exported as a default function, not a named export.","wrong":"import { template } from 'rollup-plugin-html-literals'","symbol":"default import (plugin function)","correct":"import template from 'rollup-plugin-html-literals'"},{"note":"For CJS projects, use default require. Named destructuring fails.","wrong":"const { template } = require('rollup-plugin-html-literals')","symbol":"CommonJS require","correct":"const template = require('rollup-plugin-html-literals')"},{"note":"Plugin ships TypeScript types; default import works with esModuleInterop.","wrong":"import * as template from 'rollup-plugin-html-literals'","symbol":"TypeScript import","correct":"import template from 'rollup-plugin-html-literals'"}],"quickstart":{"code":"import template from 'rollup-plugin-html-literals';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'esm'\n  },\n  plugins: [\n    template({\n      include: ['**/*.js'],\n      exclude: ['node_modules/**'],\n      failOnError: false,\n      options: {\n        minifyOptions: {\n          collapseWhitespace: true,\n          conservativeCollapse: true\n        }\n      }\n    })\n  ]\n};","lang":"typescript","description":"Basic Rollup config using the plugin to minify HTML template literals in all JS files, excluding node_modules."},"warnings":[{"fix":"Place template() before transpile plugins in the plugins array.","message":"Plugin must run before transpilation (e.g., before Babel or TypeScript) to avoid mangled code.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use minifyHTMLLiterals option to customize the minification function or configure minify-literals options accordingly.","message":"Only minifies template literals tagged with html; other tags like css or custom tags are not processed by default.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Refer to minify-literals documentation for custom minification.","message":"The minifyHTMLLiterals option is deprecated in favor of options.customMinifiers or direct minify-literals configuration.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use patterns like 'src/**/*.js' instead of just '*.js'.","message":"When using include/exclude patterns, they are relative to the project root and must match full paths after Rollup resolves them.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run npm install minify-literals --save-dev","cause":"Missing dependency minify-literals (not automatically installed as peer dependency).","error":"Error: Could not resolve 'minify-literals'"},{"fix":"Use import template from 'rollup-plugin-html-literals'","cause":"Incorrect import: using named import instead of default import.","error":"TypeError: template is not a function"},{"fix":"Move template() before transpile plugins in plugins array.","cause":"Order of plugins in Rollup config: template() after Babel/TypeScript.","error":"Error: The plugin must be placed before transpilation plugins"},{"fix":"Upgrade Rollup to ^2.0.0 or later, or use rollup-plugin-minify-html-literals for older versions.","cause":"Rollup version is <2 and not supported by this plugin.","error":"Unexpected token: punc (.) - Template literals not minified"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}