O'Reilly logo

Grunt Cookbook by Jurie-Jan Botha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wrapping Handlebars templates in CommonJS modules

In this recipe, we'll make use of the contrib-handlebars (0.8.0) plugin to wrap our compiled blog template in a CommonJS module.

Getting ready

In this example, we'll work with the basic project structure we created in the Compiling Handlebars templates recipe of this chapter. Be sure to refer to it if you are not yet familiar with its contents.

How to do it...

The following steps take us through altering our configuration so that it wraps our compiled template in a CommonJS module.

  1. First, we'll alter the configuration by adding the amd option to indicate that the compiled templates should be wrapped in a CommonJS module.
    handlebars: {
      blog: {
        options: {
          commonjs: true }, src: 'blog.hbs', dest: 'templates.js' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required