npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ya-handlebars-bundler

v2.1.3

Published

Yet Another Handlebars bundler. Read below why it's better

Downloads

9

Readme

YA Handlebars Bundler

Ya, yet another, because why not?

Handlebars Bundler is made to be a dead simple replacement for Webpack, when it comes to work with Handlebars templates, partials and helpers. It provides you basically the same functionality as if you would use Webpack + handlebars-loader. However, it's abit better and completely standalone. I'm proud of it, because it does its job like a charm. +You don't have to setup any Webpack/Gulp/Grunt/etc to use it.

Menu

TLDR it can:

  • watch over all nested, even dynamically created, files/folders
  • cache all the files in RAM
  • (re)compile only what has to be (re)compiled
  • minify and mangle output
  • bundle all the stuff into a single file

Out of the box you'll be able to use the bundle in various environments, like:

  • CommonJS: Node.js, Browserify, Webpack etc
  • AMD: RequireJS, Dojo Toolkit, ScriptManJS etc
  • Browsers without any custom loaders

Installation

npm install -g ya-handlebars-bundler

NOTICE: handlebars library (or handlebars/runtime) MUST be already included somehow in your application. In browsers it should be included before the bundle file. You can find and download latest Handlebars builds at cdnjs

Basic usage

mkdir ~/myapp
cd ~/myapp
handlebars-init # easy way to create handlebars.config.js in CWD
# (*) it will be prefilled with the default values
# (*) and some dirs: [helpers, partials, templates]
# (*) will be created and will contain some examples
vim handlebars.config.js # now it's time to edit the config
handlebars-watch # or `watch-handlebars`, it's just an alias.

NOTICE: It's recommended to run as background task handlebars-watch &

Options

Configuration file MUST be called handlebars.config.js.

Default config values:

module.exports = {
  entry: {
    helpers: 'helpers',
    partials: 'partials',
    templates: 'templates',
  },
  output: {
    path: './', // the CWD
    filename: 'handlebars.bundle.js',
    minify: false, // if true, .js will be replaced with .min.js
    // (*) as well as output will be minified and mangled
  },
  options: {
    verbose: true, // if false, less info in stdout
    // (*) stderr stream is always at its full power
  },
}

With the default config the bundler will:

  • watch over ~/myapp/helpers ~/myapp/partials ~/myapp/templates

  • compile and bundle all the stuff on the fly into ~/myapp/handlebars.bundle.js

Examples:

NOTICE: Consider, please, that Handlebars is Capitalized everywhere.

Handlebars Template Referencing

{{> nes/ted/kitty }} # nested partials
{{#capitalize message myProp="true"}}{{/capitalize}} # helpers

Handlebars Helper example

// usage: {{#capitalize message myProp="true"}}{{/capitalize}}
Handlebars.registerHelper('capitalize', (context, options) => {
  // context === message
  let myProp = options.hash.myProp
  return `you can declare multiple helpers per file, I don't do that though`
})

Node.js

npm install --save handlebars

then in anyfile.js

const Handlebars = require('handlebars')
require('./handlebars.bundle.js') // That's it!
/**
 * Now you're free to use templates, partials and helpers
 * as you usually do
 */
const html = Handlebars.templates.kittens({})
// or
const html = Handlebars.templates['kittens']({})
// or let's say we have nested file `~/myapp/templates/partials/nes/ted/kitty.hbs`
const html = Handlebars.partials['nes/ted/kitty']({})

RequireJS

// Runtime build will be enough, you don't really need the full Handlebars anymore
require(['handlebars.runtime.amd.min.js', './handlebars.bundle.js'], Handlebars => {
  // the same as for Node.js
});

Browsers

<!-- Runtime build will be enough, you don't really need the full Handlebars anymore -->
<script src="handlebars.runtime-v4.0.11.min.js"></script>
<script src="handlebars.bundle.js"></script>
<script>
  // the same as for Node.js
</script>