Registry / devops / ya-handlebars-bundler

ya-handlebars-bundler

JSON →
library2.1.3jsnpmunverified

YA Handlebars Bundler is a command-line interface (CLI) tool designed as a lightweight, standalone alternative to complex build tools like Webpack or Gulp for compiling Handlebars.js templates, partials, and helpers. The current stable version is 2.1.3. It operates by watching specified directories for changes, caching files in RAM, and recompiling only affected assets into a single JavaScript bundle. Key differentiators include its zero-setup nature, ability to monitor dynamically created files, and output bundles compatible with CommonJS (Node.js, Browserify), AMD (RequireJS), and direct browser inclusion without custom loaders. The tool also supports minification and mangling of the output, making it suitable for both development and production environments. It focuses on providing a streamlined templating workflow without the overhead of a full-fledged module bundler. The release cadence appears to be feature-driven rather than time-boxed, providing stability for users.

npm install ya-handlebars-bundler
INSTALL
IMPORT
SIG · YA-HANDLEBARS-BUND
Y
ya-handlebars-bundler
devopsjavascriptv2.1.3
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

CLI Commands
npm install -g ya-handlebars-bundler handlebars-init handlebars-watch
import { handlebarsWatch } from 'ya-handlebars-bundler'
ya-handlebars-bundler is primarily a command-line interface tool. It is installed globally or locally and invoked via its CLI commands, not directly imported into JavaScript code. The generated bundle is then consumed.
Handlebars.templates
const Handlebars = require('handlebars'); require('./handlebars.bundle.js'); const html = Handlebars.templates.myTemplate({});
import { templates } from 'handlebars.bundle.js'; const html = templates.myTemplate({});
After the generated `handlebars.bundle.js` is loaded (via `require` or `<script>`), it populates the global or imported `Handlebars` object. Templates are then accessed through `Handlebars.templates` (or `Handlebars.partials`). Ensure the `handlebars` library is loaded *before* the bundle in browsers.
Handlebars.partials
const Handlebars = require('handlebars'); require('./handlebars.bundle.js'); const partialHtml = Handlebars.partials['my/nested/partial']({});
import { partials } from './handlebars.bundle.js'; const partialHtml = partials['my/nested/partial']({});
Similar to templates, partials are exposed on the `Handlebars` object. The bundle automatically registers partials under their respective paths (e.g., `nes/ted/kitty` for `~/myapp/partials/nes/ted/kitty.hbs`). The main `Handlebars` library must be present first.

This quickstart guides through global installation, project initialization with default configuration, continuous bundling, and how to consume the generated Handlebars bundle in a Node.js environment.

/* Install globally */ npm install -g ya-handlebars-bundler /* Create a new project directory */ mkdir my-handlebars-app cd my-handlebars-app /* Initialize default configuration and example files */ handlebars-init /* Review and adjust handlebars.config.js */ // module.exports = { // entry: { // helpers: 'helpers', // partials: 'partials', // templates: 'templates', // }, // output: { // path: './', // filename: 'handlebars.bundle.js', // minify: false, // }, // options: { // verbose: true, // }, // }; /* Start the bundler in watch mode (run as background task in production) */ handlebars-watch & /* In your Node.js application (e.g., app.js) */ // First, install the handlebars runtime library // npm install --save handlebars const Handlebars = require('handlebars'); // Load the generated bundle. This will populate Handlebars.templates and Handlebars.partials. require('./handlebars.bundle.js'); // Assuming you have a template named 'kittens.hbs' in your 'templates' directory, // and a partial 'nes/ted/kitty.hbs' in your 'partials' directory. const templateData = { message: 'Hello from Handlebars!' }; const kittenHtml = Handlebars.templates.kittens(templateData); const nestedPartialHtml = Handlebars.partials['nes/ted/kitty'](templateData); console.log('Kitten Template Output:', kittenHtml); console.log('Nested Partial Output:', nestedPartialHtml); // Example of using a custom helper (assuming 'capitalize' helper is defined in helpers/capitalize.js) // Handlebars.registerHelper('capitalize', (context, options) => { /* ... */ }); // const capitalizedMessage = Handlebars.helpers.capitalize('my message'); // Direct helper call
handlebars --version
Debug
Known issues
gotchaThe `handlebars` (or `handlebars/runtime`) library is a mandatory peer dependency for your application, not included by this bundler. It must be provided in the runtime environment (e.g., via `npm install handlebars` for Node.js or a `<script>` tag for browsers) before the generated bundle loads.
fix
Ensure `handlebars` is installed (`npm install handlebars`) and loaded into your application's context before the `handlebars.bundle.js` file is loaded. For browsers, include `<script src="path/to/handlebars.js"></script>` before your bundle.
affects: >=1.0.0
gotchaThe configuration file `handlebars.config.js` in the Current Working Directory (CWD) is strictly required for the `handlebars-watch` and `handlebars-init` commands to function correctly. Without it, the bundler cannot determine entry points or output settings.
fix
Run `handlebars-init` in your project's root directory to generate a default `handlebars.config.js` file, then customize it as needed.
affects: >=1.0.0
gotchaWhen `output.minify` is set to `true` in `handlebars.config.js`, the output filename automatically changes from `handlebars.bundle.js` to `handlebars.bundle.min.js`. Be aware of this naming convention when referencing the generated file in your application.
fix
Adjust your `require()` paths or `<script>` tags to match the minified filename (`handlebars.bundle.min.js`) when minification is enabled.
affects: >=1.0.0
gotchaThe `handlebars-watch` command runs continuously. For production environments or headless servers, it's recommended to run it as a background process (e.g., `handlebars-watch &` on Linux/macOS) or as part of a build script that only runs once (`handlebars-build`).
fix
Use appropriate daemonization techniques for your operating system or integrate it into a CI/CD pipeline. For one-off builds, check if a non-watching 'build' command is available or terminate the `watch` process after the initial build.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: Handlebars is not defined
The main Handlebars.js library was not loaded before the `handlebars.bundle.js` file, which expects `Handlebars` to be globally available or a pre-imported CommonJS module.
fix
For Node.js, ensure `const Handlebars = require('handlebars');` is executed before `require('./handlebars.bundle.js');`. For browsers, include `<script src="path/to/handlebars.js"></script>` before the bundle script.
Error: ENOENT: no such file or directory, stat 'handlebars.config.js'
The `handlebars-watch` or `handlebars-init` command was run in a directory where `handlebars.config.js` does not exist.
fix
Navigate to the project's root directory or the directory containing your `handlebars.config.js` file. If it doesn't exist, run `handlebars-init` to create one.
TypeError: Handlebars.templates.myTemplate is not a function
Either the template file 'myTemplate.hbs' is missing from the configured `entry.templates` directory, or there's a typo in the template name when trying to access it via `Handlebars.templates`.
fix
Verify that your template files exist in the `entry.templates` path specified in `handlebars.config.js` and that the filename (without extension) exactly matches the property you're trying to access on `Handlebars.templates`.
command not found: handlebars-init
The `ya-handlebars-bundler` package, which provides the `handlebars-init` and `handlebars-watch` commands, was not installed globally or is not in your system's PATH.
fix
Install the package globally using `npm install -g ya-handlebars-bundler` or ensure your local `node_modules/.bin` directory is in your PATH.
Upgrade
Version history
2.1.3latest on npm
Audit
Dependencies
handlebarsrequiredThis bundler precompiles Handlebars templates, but the Handlebars.js runtime library itself (or the full Handlebars library) must be included separately in your application for the bundled templates to function. It is a critical runtime dependency.
Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
ya-handlebars-bundler — npm install ya-handlebars-bundler · libregistry