esbuild-plugin-handlebars
raw JSON → 1.0.3 verified Mon Apr 27 auth: no javascript
An esbuild plugin that precompiles Handlebars templates during the build process. Current stable version is 1.0.3. It integrates with esbuild's plugin system to handle .hbs files, allowing you to bundle Handlebars templates into your output. Compared to other Handlebars loaders, it is lightweight and focused on esbuild, with options for additional helpers, partials, and precompile options. The package has a simple API and is published on npm with regular maintenance.
Common errors
error Error: Cannot find module 'esbuild-plugin-handlebars' ↓
cause Package not installed or not in node_modules.
fix
Run 'npm install esbuild-plugin-handlebars --save-dev' or 'yarn add -D esbuild-plugin-handlebars'.
error TypeError: esbuild_plugin_handlebars_1.default is not a function ↓
cause Using CommonJS require() on an ESM-only package.
fix
Use import statement or dynamic import().
error Error: The plugin 'esbuild-plugin-handlebars' is not a function or object ↓
cause Incorrect usage of the plugin in esbuild config.
fix
Ensure you call the default export as a function: plugins: [handlebarsPlugin()]
Warnings
gotcha If you use CommonJS require(), the import will fail because the package is ESM-only. ↓
fix Use dynamic import() or switch to ESM. For Node.js, set "type": "module" in package.json.
deprecated No deprecated features at this time. ↓
fix N/A
breaking No breaking changes in version 1.0.3. ↓
fix N/A
Install
npm install esbuild-plugin-handlebars yarn add esbuild-plugin-handlebars pnpm add esbuild-plugin-handlebars Imports
- default wrong
const handlebarsPlugin = require('esbuild-plugin-handlebars')correctimport handlebarsPlugin from 'esbuild-plugin-handlebars' - handlebarsPlugin (as named import) wrong
const { handlebarsPlugin } = require('esbuild-plugin-handlebars')correctimport { handlebarsPlugin } from 'esbuild-plugin-handlebars' - HandlebarsOptions (type)
import type { HandlebarsOptions } from 'esbuild-plugin-handlebars'
Quickstart
import esbuild from 'esbuild';
import handlebarsPlugin from 'esbuild-plugin-handlebars';
await esbuild.build({
entryPoints: ['src/index.js'],
outfile: 'dist/bundle.js',
bundle: true,
plugins: [handlebarsPlugin({
additionalHelpers: {},
additionalPartials: {},
precompileOptions: {}
})],
});