dustc-commonjs
Transforms a compiled Dust template into a CommonJS module.
Installation
npm install dustc-commonjs --save
Why?
Standard Dust modules compile down to JavaScript code that registers a compiled template function using a given template name and the compiled output assumes that there is a global dust
variable (globals are evil). By producing a CommonJS module as output the template can be loaded using the standard Node.js module loading system based on require
.
Usage
Given the following sample template:
Hello {name}!
And the following sample program:
var templatePath = ;
The output compiled template will be similar to the following:
{moduleexports=body_0;{return chk;}return body_0;};
Notice the usage of module.exports
.
In comparison, the standard compiled output (that is _not) a CommonJS module) will be similar to the following:
{moduleexports=body_0;{return chk;}return body_0;};