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

handlebars-entry-loader

v1.2.1

Published

Webpack loader to enable using Handlebars templates as entry points

Downloads

8

Readme

Handlebars Entry Loader

NPM version Build status Dependency status bitHound dependencies

Webpack loader to enable using Handlebars templates as entry points.

Similar to all of the other Handlebars loaders, but with 100% more TypeScript and goats!

Includes support for:

  • Data
  • Partials
  • Helpers
  • Decorators

Usage


const ExtractTextPlugin = require('extract-text-webpack-plugin');

const ExtractHandlebars = new ExtractTextPlugin({
    allChunks: false,
    filename: '[name].html'
});

module.exports = {
    entry: {
        'index': 'src/templates/homepage.hbs'
    },
    module: {
        loaders: [
            {
                test: /\.hbs$/,
                use: ExtractHandlebars.extract([
                    {
                        loader: 'html-loader',
                        options: {
                            minimize: false
                        }
                    },
                    {
                        loader: 'handlebars-entry-loader',
                        options: {
                            partials: 'src/partials/**/*.hbs',
                            helpers: 'src/helpers/**/*.helper.js',
                            data: 'src/data.json'
                        }
                    },
                ])
            },
        ]
    },
    plugins: [
        ExtractHandlebars
    ],
    output: {
        path: 'dist/'
    }
}

See src/examples for more complex configurations.

Options

Data

data: {}

Data to pass to the handlebars template.

Can either be a JavaScript Object {foo: 'bar'} or a path to a JSON file to load.

Partials

File glob to load Handlebars Partials from.

Defaults to null (won't load any partials)

Example:

config:

partials: 'src/partials/**/*.hbs'

src/partials/foo/bar.hbs:

<p>Hello {{name}}, I am foo/bar</p>

something.hbs:

{{> src/partials/foo/bar.hbs name="Something" }}

Partial namer

By default partials will use the file name minus extension as the partial name, this may be undesirable (e.g. multiple partials with the same name in different directories)

To override this behaviour, provide a partialNamer function:

partialNamer: function(partial) {
    return partial.replace('src/partials/', '').replace('.hbs', '');
}

something.hbs

{{> foo/bar }}

Helpers

File glob to load Handlebars Partials from.

Defaults to null (won't load any partials)

Example:

config:

helpers: 'src/helpers/**/*.helper.js'

src/helpers/json.helper.js:

exports.default = function(data) {
    return JSON.stringify(data, null, ' ');
};

something.hbs:

<pre>{{src/helpers/json.helper.js someJSObject}}</pre>

Helper namer

helperNamer: helper => helper

By default helpers will use the file name minus extension as the helper name, this may be undesirable (e.g. multiple helpers with the same name in different directories)

To override this behaviour, provide a helperNamer function:

helperNamer: function(helper) {
    return helper.replace('src/helpers/', '').replace('.js', '');
}

something.hbs

<pre>{{json someJSObject}}</pre>

Decorators

Decorators follow the same config rules as helpers, using the following options:

decorators: 'src/decorators/**/*.js',
helperNamer: function() {...}

Debug

Set to true to wrap Handlebars templates & partials with HTML comments containing debugging information (name, path, data, etc.)

Useful to enable based on NODE_ENV:

debug: process.env.NODE_ENV !== 'production'

Prevent JS output

By default we prevent Webpack from emitting a .js file with each Handlebars entry point.

If this is causing issues with other loaders, you can turn it off:

preventJsOutput: false