rollup-plugin-hbs
raw JSON → 1.2.6 verified Mon Apr 27 auth: no javascript deprecated
A minimal Rollup plugin for bundling Handlebars templates. Version 1.2.6 is the latest stable release, last updated in 2020. It compiles .hbs (or custom extension) templates into precompiled JavaScript functions, integrating with Handlebars runtime. Compared to other Handlebars Rollup plugins like rollup-plugin-handlebars-plus, this package offers a simpler API, sourcemap support, partial detection based on filename prefix, and whitespace optimization. It requires Handlebars, Rollup >=0.62.0, and rollup-pluginutils as peer dependencies. Note that the plugin has not been updated for Rollup 2+/3+ and may be incompatible with modern Rollup versions; consider using @rollup/plugin-handlebars instead.
Common errors
error Error: Cannot find module 'rollup-plugin-hbs' ↓
cause Package not installed or missing from node_modules
fix
npm install rollup-plugin-hbs --save-dev
error TypeError: hbs is not a function ↓
cause Using CommonJS require() instead of ESM import
fix
Use 'import hbs from 'rollup-plugin-hbs'' in an ESM context
error Error: Could not resolve './template.hbs' from 'src/main.js' ↓
cause Rollup cannot resolve .hbs files; plugin not configured correctly
fix
Ensure rollup-plugin-hbs is added to plugins array and templateExtension matches file extension
error Error: The 'handlebars' module is not installed ↓
cause Handlebars is a peer dependency not installed
fix
npm install handlebars
Warnings
deprecated Package is no longer maintained; no updates since 2020 ↓
fix Migrate to @rollup/plugin-handlebars or rollup-plugin-handlebars-plus
breaking Incompatible with Rollup >=2.0 due to plugin API changes ↓
fix Use an older version of Rollup (0.x) or switch to a maintained plugin
gotcha Template filenames starting with '_' are automatically treated as partials and not included in output if not imported ↓
fix Ensure partials are imported explicitly or adjust isPartial logic
gotcha Sourcemaps may be incomplete due to lack of Rollup 2+ support ↓
fix Disable sourcemaps or use alternatives
deprecated rollup-pluginutils is deprecated; plugin uses its functionality internally ↓
fix Not directly fixable; migrate to a plugin that uses modern Rollup APIs
Install
npm install rollup-plugin-hbs yarn add rollup-plugin-hbs pnpm add rollup-plugin-hbs Imports
- hbs wrong
const hbs = require('rollup-plugin-hbs')correctimport hbs from 'rollup-plugin-hbs' - default wrong
import { hbs } from 'rollup-plugin-hbs'correctimport hbs from 'rollup-plugin-hbs' - Handlebars wrong
import Handlebars from 'rollup-plugin-hbs'correctimport Handlebars from 'handlebars'
Quickstart
// rollup.config.js
import hbs from 'rollup-plugin-hbs';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'src/main.js',
output: { file: 'bundle.js', format: 'iife' },
plugins: [
resolve(),
commonjs(),
hbs({
handlebars: {
id: 'handlebars',
options: { sourceMap: true },
optimize: true
},
templateExtension: '.hbs',
isPartial: (name) => name.startsWith('_')
})
]
};
// src/main.js
import template from './template.hbs';
const html = template({ name: 'world' });
console.log(html);
// src/template.hbs
<p>Hello {{name}}!</p>