handlebars-loader

handlebars loader module for webpack

npm install handlebars-loader
3 downloads in the last day
24 downloads in the last week
68 downloads in the last month

handlebars-loader

A handlebars template loader for webpack.

General Usage

webpack configuration

{
  ...
  module: {
    loaders: [
      ...
      { test: /\.handlebars$/, loader: "handlebars-loader" }
    ]
  }
}

Your JS making use of the templates

var template = require("./file.handlebars");
// => returns file.handlebars content as a template function

Details

The loader resolves partials and helpers automatically. They are looked up relative to the current directory or as a module if you prefix with $.

A file "/folder/file.handlebars".
{{> partial}} will reference "/folder/partial.handlebars".
{{> ../partial}} will reference "/partial.handlebars".
{{> $module/partial}} will reference "/folder/node_modules/module/partial.handlebars".
{{helper}} will reference the helper "/folder/helper.js" if this file exists.
{{../helper}} {{$module/helper}} are resolved similarly to partials.

See webpack documentation for more information regarding loaders.

Full example

See example folder in this repo. The example is now fully runnable and demonstrates a number of concepts (using partials and helpers) -- just run webpack in that directory to produce dist/bundle.js in the same folder.

License

MIT (http://www.opensource.org/licenses/mit-license)

npm loves you