Registry / web-framework / rollup-plugin-handlebars-precompiler

rollup-plugin-handlebars-precompiler

JSON →
library1.0.2jsnpmunverified

Rollup plugin that precompiles Handlebars templates into ES modules. Version 1.0.2 requires Node >=18 and Handlebars as a peer dependency. Generates ESM-only modules with TypeScript support, automatic partial detection, source maps, and convenient DOM integration via exported RawTemplate and Template functions. Unlike other Handlebars rollup plugins, it outputs DocumentFragment-ready modules with type definitions.

npm install rollup-plugin-handlebars-precompiler
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-HAND
R
rollup-plugin-handlebars-precompiler
web-frameworkjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

rollup-plugin-handlebars-precompiler
import handlebarsPrecompiler from 'rollup-plugin-handlebars-precompiler'
const handlebarsPrecompiler = require('rollup-plugin-handlebars-precompiler')
Package is ESM-only; CommonJS require will fail. Use default import only.
Template
import Template, { RawTemplate } from './template.hbs'
import { Template } from './template.hbs'
Default export is the Template function; RawTemplate is a named export.
RawTemplate
import { RawTemplate } from './template.hbs'
import RawTemplate from './template.hbs'
RawTemplate is not the default export; must use named import syntax.

Shows rollup config with plugin setup and usage of imported Handlebars template to append a DocumentFragment to the DOM.

// rollup.config.js import handlebarsPrecompiler from 'rollup-plugin-handlebars-precompiler' export default { input: 'src/main.js', output: { dir: 'dist', format: 'esm' }, plugins: [ handlebarsPrecompiler({ // Include handlebars helpers from a specific file helpers: 'src/helpers/**/*.js', // enable source maps sourceMap: true }) ] } // src/main.js import Template from './component.hbs' const app = document.getElementById('app') const context = { message: 'Hello' } app.appendChild(Template(context))
Debug
Known issues
breakingPackage requires Node >=18 and ESM-only — no CommonJS support.
fix
Use Node 18+ and import via ESM syntax only.
affects: >=1.0.0
gotchaHandlebars must be installed as a direct dependency of your project, not just this plugin.
fix
Run 'npm install handlebars' or 'pnpm add handlebars' in your project.
affects: >=1.0.0
gotchaGenerated modules use the Handlebars runtime from 'node_modules/handlebars/lib/handlebars.runtime.js' — ensure it is bundled.
fix
Make sure your bundler resolves the runtime; it is included automatically if rollup processes node_modules.
affects: >=1.0.0
deprecatedThe plugin may not handle all Handlebars features; test partials and helpers thoroughly.
fix
Validate template compilation with the plugin's specific configuration for partials and helpers.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-handlebars-precompiler/dist/index.js from /path/to/rollup.config.js not supported.
Attempting to use CommonJS require to load the ESM-only plugin.
fix
Change require() to import and ensure rollup.config.js uses ESM (e.g., rename to .mjs or set type: module in package.json).
Error: Cannot find module 'handlebars'
Handlebars is not installed as a project dependency.
fix
Run 'npm install handlebars' or 'pnpm add handlebars' in your project.
Cannot find module './template.hbs' or its corresponding type declarations.
TypeScript does not recognize .hbs imports; missing module declaration.
fix
Add a global type declaration: declare module '*.hbs' { import type { TemplateFunction } from 'rollup-plugin-handlebars-precompiler'; const tmpl: TemplateFunction; export default tmpl; export const RawTemplate: (context?: any, options?: any) => string; }
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
handlebarsrequiredThe Handlebars runtime is bundled into generated modules; users must install it separately.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-handlebars-precompiler — npm install rollup-plugin-handlebars-precompiler · libregistry