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.
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.
The following steps take us through altering our configuration so that it wraps our compiled template in a CommonJS module.
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' } }
Using the
namespace
option, we can now also specify that we no longer want the compiled templates to be contained within theJST
namespace, since they will now be contained within a module:handlebars: { blog:...