dust-template-loader
v1.0.3
Published
dustjs loader module for webpack with option ?whitespacestrue to preserves whitespaces in compilted template
Downloads
6
Readme
dust loader for webpack
Compiles dust templates and exports the compiled functions, allowing for rendering of the templates in a browser environment. This version has option ?whitespacestrue to preserves whitespaces in compilted template.
Usage
var template = require("dust-template?whitespacestrue!./template-file.dust");
// => returns template-file.dust compiled as template function with name "template-file" and preserved whitespaces (good for DEV environment)
or
var template = require("dust-template!./template-file.dust");
// => returns template-file.dust compiled as template function with name "template-file" and without whitespaces (good for PRODUCTION environment)
Recommended config
var whiteSpaces = process.env.NODE_ENV != 'production' ? 'whitespacestrue' : 'nowhitespaces';
module.exports = {
module: {
loaders: [
{ test: /\.dust$/, loader: 'dust-loader?' + whiteSpaces},
]
}
};
Then you only need to write: require("./template-name.dust")
Rendering a template
You will need to bundle the dust core in your pack in order to render the compiled templates. Use file name to render template.
require('./views/foo/template-name.tpl');
dust.render('template-name', context, function(err, result){
// result holds the rendered HTML code
});
License
MIT (http://www.opensource.org/licenses/mit-license.php)