{"id":22181,"library":"rollup-plugin-posthtml-template","title":"rollup-plugin-posthtml-template","description":"A Rollup plugin that imports HTML files as strings and optionally transforms them with PostHTML. Version 1.3.0 is the latest stable release. It enables importing .html files directly in JavaScript, supports custom PostHTML plugins (e.g., posthtml-include), template interpolation, custom parsers (e.g., sugarml), and directives. Differentiators: lightweight, focuses on PostHTML integration for HTML transformations within Rollup builds, with first-class TypeScript support.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/Vanilla-IceCream/rollup-plugin-posthtml-template","tags":["javascript","Rollup","PostHTML"],"install":[{"cmd":"npm install rollup-plugin-posthtml-template","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-posthtml-template","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-posthtml-template","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - required to function as a Rollup plugin","package":"rollup","optional":false},{"reason":"Peer dependency - PostHTML core library used for HTML transformations","package":"posthtml","optional":false}],"imports":[{"note":"Default export, ESM only. Requires “rollup” and “posthtml” as peer dependencies.","wrong":"const posthtml = require('rollup-plugin-posthtml-template')","symbol":"default (posthtml)","correct":"import posthtml from 'rollup-plugin-posthtml-template'"},{"note":"Type import only; not a runtime export.","wrong":"import { RollupPostHTMLTemplateOptions } from 'rollup-plugin-posthtml-template' (causing runtime error)","symbol":"RollupPostHTMLTemplateOptions","correct":"import type { RollupPostHTMLTemplateOptions } from 'rollup-plugin-posthtml-template'"},{"note":"The plugin returns a Rollup Plugin object; no additional types exported.","wrong":"","symbol":"Plugin (type)","correct":"import type { Plugin } from 'rollup'"}],"quickstart":{"code":"// rollup.config.js\nimport posthtml from 'rollup-plugin-posthtml-template';\n\nexport default {\n  input: 'main.js',\n  output: {\n    file: 'bundle.js',\n    format: 'iife'\n  },\n  plugins: [\n    posthtml()\n  ]\n};\n\n// main.js\nimport hello from './hello.html';\ndocument.querySelector('#app').innerHTML = hello;\n\n// hello.html\n<p>Hello, World!</p>","lang":"javascript","description":"Configures Rollup to import HTML files as strings using the PostHTML plugin."},"warnings":[{"fix":"Install both: npm install rollup posthtml --save-dev","message":"Plugin requires peer dependencies 'rollup' and 'posthtml'. Missing them or mismatched versions causes silent failures.","severity":"gotcha","affected_versions":"*"},{"fix":"If template option enabled, call the import as a function: `import tmpl from './file.html'; tmpl({ data })`","message":"When using 'template: true', the exported module is a function, not a string. Using it as a string will result in a runtime error.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Pass a string parser name or a PostHTML parser object instead.","message":"The 'parser' option accepting a function is deprecated. Use the PostHTML parser API directly.","severity":"deprecated","affected_versions":">=1.2"},{"fix":"Refer to the PostHTML documentation for the correct plugin format.","message":"Type definitions are not exported for the options object. Using incorrect options (e.g., 'plugins' with wrong shape) may not trigger TypeScript errors.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Consider using 'rollup-plugin-hot' or configure your dev server to reload on HTML changes.","message":"The plugin does not support Hot Module Replacement (HMR) in development. Changes to HTML files require a manual rebuild.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run: npm install rollup-plugin-posthtml-template --save-dev","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'rollup-plugin-posthtml-template'"},{"fix":"Use: import posthtml from 'rollup-plugin-posthtml-template' (default import)","cause":"Attempting to use posthtml as a named export instead of default export.","error":"TypeError: posthtml is not a function"},{"fix":"Install missing peer dependencies: npm install posthtml rollup --save-dev","cause":"Peer dependency not installed.","error":"Error: Cannot find module 'posthtml' (or 'rollup')"},{"fix":"Ensure the project uses ESM (type: \"module\" in package.json) and import syntax.","cause":"Using CommonJS require in an ESM context or vice versa.","error":"export 'default' (imported as 'posthtml') was not found in 'rollup-plugin-posthtml-template'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}