1.0.3 • Published 8 years ago

dust-template-loader v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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

Documentation: Using loaders

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)