Registry / serialization / rollup-plugin-posthtml-template

rollup-plugin-posthtml-template

JSON →
library1.3.0jsnpmunverified

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.

npm install rollup-plugin-posthtml-template
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-POST
R
rollup-plugin-posthtml-template
serializationjavascriptv1.3.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default (posthtml)
✓ import posthtml from 'rollup-plugin-posthtml-template'
✗ const posthtml = require('rollup-plugin-posthtml-template')
Default export, ESM only. Requires “rollup” and “posthtml” as peer dependencies.
RollupPostHTMLTemplateOptions
✓ import type { RollupPostHTMLTemplateOptions } from 'rollup-plugin-posthtml-template'
✗ import { RollupPostHTMLTemplateOptions } from 'rollup-plugin-posthtml-template' (causing runtime error)
Type import only; not a runtime export.
Plugin (type)
✓ import type { Plugin } from 'rollup'
The plugin returns a Rollup Plugin object; no additional types exported.

Configures Rollup to import HTML files as strings using the PostHTML plugin.

// rollup.config.js import posthtml from 'rollup-plugin-posthtml-template'; export default { input: 'main.js', output: { file: 'bundle.js', format: 'iife' }, plugins: [ posthtml() ] }; // main.js import hello from './hello.html'; document.querySelector('#app').innerHTML = hello; // hello.html <p>Hello, World!</p>
Debug
Known issues
gotchaPlugin requires peer dependencies 'rollup' and 'posthtml'. Missing them or mismatched versions causes silent failures.
fix
Install both: npm install rollup posthtml --save-dev
affects: *
gotchaWhen using 'template: true', the exported module is a function, not a string. Using it as a string will result in a runtime error.
fix
If template option enabled, call the import as a function: `import tmpl from './file.html'; tmpl({ data })`
affects: >=1.0
deprecatedThe 'parser' option accepting a function is deprecated. Use the PostHTML parser API directly.
fix
Pass a string parser name or a PostHTML parser object instead.
affects: >=1.2
gotchaType definitions are not exported for the options object. Using incorrect options (e.g., 'plugins' with wrong shape) may not trigger TypeScript errors.
fix
Refer to the PostHTML documentation for the correct plugin format.
affects: >=1.0
gotchaThe plugin does not support Hot Module Replacement (HMR) in development. Changes to HTML files require a manual rebuild.
fix
Consider using 'rollup-plugin-hot' or configure your dev server to reload on HTML changes.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-posthtml-template'
Package not installed or missing from node_modules.
fix
Run: npm install rollup-plugin-posthtml-template --save-dev
TypeError: posthtml is not a function
Attempting to use posthtml as a named export instead of default export.
fix
Use: import posthtml from 'rollup-plugin-posthtml-template' (default import)
Error: Cannot find module 'posthtml' (or 'rollup')
Peer dependency not installed.
fix
Install missing peer dependencies: npm install posthtml rollup --save-dev
export 'default' (imported as 'posthtml') was not found in 'rollup-plugin-posthtml-template'
Using CommonJS require in an ESM context or vice versa.
fix
Ensure the project uses ESM (type: "module" in package.json) and import syntax.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency - required to function as a Rollup plugin
posthtmlrequiredPeer dependency - PostHTML core library used for HTML transformations
Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-posthtml-template — npm install rollup-plugin-posthtml-template · libregistry